Craig Grummitt – Before I forget

Discoveries in Swift and iOS development.

,

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]

 


Comments

4 responses to “Communication between objects in Objective C and Swift compared with ActionScript – Part 2”

  1. […] between objects in Objective C and Swift compared with ActionScript: Part 1: Callbacks Part 2: Actions Part 3: Delegates Part 4: Blocks/Closures Part 5: […]

  2. […] Part 2: Actions Part 3: Delegates Part 4: Blocks/Closures And then in Part 5 I’ll come back to talk about our familiar friend Event! […]

Leave a Reply

Your email address will not be published. Required fields are marked *