3 ms·
I would suggest going with Swift, but learning enough about Objective-C concepts to use the Cocoa APIs. There is a guide to interoperability between the two lan
by austinz 12y ago
I would suggest going with Swift, but learning enough about Objective-C concepts to use the Cocoa APIs. There is a guide to interoperability between the two languages on the developer site.
For example, some sample code to call a method (here, one named 'upCommand') whenever the user swipes in the 'up' direction looks like this:
let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("upCommand"))
upSwipe.numberOfTouchesRequired = 1
upSwipe.direction = UISwipeGestureRecognizerDirection.Up
self.addGestureRecognizer(upSwipe)
A more idiomatic way in Swift to create a gesture recognizer might be to assign a closure to execute whenever the swipe is recognized.
However, because of the way Objective-C and Cocoa works, you need to define the target of the action as a string literal describing the method name, encapsulated in a 'Selector' object. This is a fundamental Objective-C feature that shows up as a common idiom in the Cocoa APIs. If you didn't know what a selector was, you might have trouble translating this API into working Swift code, since Swift has no real equivalent construct (except the 'Selector()' class described above, there only for backwards compatibility).