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

When I began using Objective C, coming from ActionScript, I was a little overwhelmed at the myriad ways that a child component can send messages to its parent. ActionScript seems sort of easy now, since generally (at least since AS3) most of this communication is done with events! The following is a comparison of the various types of child->parent communication that are employed by AS3 and Objective C/Swift.

Callbacks

A callback is basically when a parent tells a child which of its methods it wants the child to call when a certain event occurs.

ActionScript

Callbacks were more common in AS2 than AS3, but some still lingered around where the adobe team never got around to updating the API, for example in NetStream:

var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onCuePoint = ns_onCuePoint;
function ns_onCuePoint(item:Object):void {
    trace(item.name + "\t" + item.time);
}

In this case, the child ns notified its parent of a cuepoint by calling the callback method defined in its ‘onCuePoint’ variable.

Objective C/Swift

Objective C and Swift perform callbacks in several ways, I’m going to look at these in the following posts:

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!

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

Tagged with:
Posted in Flash, Objective C, Swift
One comment on “Communication between objects in Objective C and Swift compared with ActionScript Part I

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: