I am new to Objective C and I am trying to implement an async library which works with callbacks. I need to figure out a way to pass callback methods as args to my async methods so that the callback can be invoked when the task is finished.
What is the best way to achieve this in Objective C? In Python, for example I could easily pass a function, but in Objective C it seems selectors are the way to go(?).
Can anyone point me to an example from where I can get some ideas?
Thanks in advance.
Selectors are ONE way to go... the alternative is to create a protocol and to require invokers of your API to provide a "delegate" object that implements the protocol. Then you can invoke the required selectors of that protocol on the delegate object that you have been given. Each has its advantages and disadvantages.
Example using selectors: NSThread:detachNewThreadSelector:toTarget:withObject
Example using delegates:NSXMLParser:setDelegate + NSXMLParser:parse
I think I have found the answer to my question in this question.
This example code at Apple's developer site was very useful.