Communication between objects in Objective C and Swift compared with ActionScript – Part 2

Actions in Objective C and Swift

One way that Cocoa implements callbacks using Actions in the Interface Builder. Some display objects can call actions in your ViewController. You can connect the object to a method in your custom ViewController class by control dragging from the object to a class, and selecting ‘Action’. You can then choose the action(if there is more than one action available) and name the method in your code to call. It will then highlight that this method is connected to an item in the Interface Builder with the keyword IBAction and a filled circle. You can see the actions defined for an object in the Connections Inspector.

Objective C:

[sourcecode language=”objc”]
– (IBAction)didTapButton:(id)sender {
}
[/sourcecode]

Swift:

[sourcecode language=”objc”]
@IBAction func didTapButton(sender : AnyObject) {
}
[/sourcecode]

 

Unknown's avatar

iOS development with Swift - book: https://manning.com/books/ios-development-with-swift video course: https://www.manning.com/livevideo/ios-development-with-swift-lv

Tagged with:
Posted in Objective C, Swift
2 comments on “Communication between objects in Objective C and Swift compared with ActionScript – Part 2

Leave a Reply to Swift resources for Flash and ActionScript developers - Easy Native ExtensionsCancel reply

Discover more from Before I forget...

Subscribe now to keep reading and get access to the full archive.

Continue reading