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:

- (IBAction)didTapButton:(id)sender {
}

Swift:

@IBAction func didTapButton(sender : AnyObject) {
}

 

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

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: