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!

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

Facebook photo

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

Connecting to %s

%d bloggers like this: