Delegates

0 views
Skip to first unread message

offwhite

unread,
Oct 21, 2009, 12:47:30 PM10/21/09
to Midwest iPhone SDK Developers
http://mwiphonesdk.googlegroups.com/web/Delegates.zip?gda=7eavhD8AAADFNN8n0YeieKdYwMofp98sh5GefkV4PmDKNYCJiK3ZK1F_8UjA5pLR-0vnwZAwoj-ccyFKn-rNKC-d1pM_IdV0

In order to work with async calls, like downloading a lot of data in
chunks, and then telling the caller that the download is done it is
necessary to make a callback. This is extremely easy in JavaScript by
passing in a callback function. In .NET you would publish an event
from the worker and subscribe to that event from the caller and raise
the event to tell the caller when the action has occurred. In
Objective-C I have learned this is done very differently with
delegates. It took me a while to wrap my head around it.

I put together a sample for an iPhone app which does what you need to
do to make a callback/delegate. It is actually pretty easy. You use
the @prototype and @optional directives to define method signatures
which act as delegates so that when you try calling them in your code
that you do not get compiler warnings.

The sample project is uploaded to this group and is linked at the top
of this message.

I found the following post on StackOverflow.com to be most useful.

http://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c
Reply all
Reply to author
Forward
0 new messages