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) {
}

 

Interactive developer, Author - iOS development with Swift - book coming 2017 https://manning.com/books/ios-development-with-swift

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: