5 ways to do the callbacks in objective C and iOS dev

1. Selector
http://stackoverflow.com/questions/3482344/what-actually-is-a-selector

An example
http://stackoverflow.com/questions/10758926/add-selector-to-uibutton
[button addTarget:yourObject action:@selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];

2. NSNotifications
In a way (and in syntax too) it’s similar to Selector, but used in different settings.

example here
http://www.cocoanetics.com/2009/08/love-to-be-notified/

3. Delegate methods
e.g., UIAlert view, UITextField delegate

customized method (example)
http://www.raywenderlich.com/29474/ipad-for-iphone-developers-101-in-ios-6-custom-input-view-tutorial

4. Blocks
https://developer.apple.com/library/mac/#featuredarticles/BuildingWithBlocks/_index.html

example
http://stackoverflow.com/questions/7180552/implementing-a-method-taking-a-block-to-use-as-callback

5. GCD
My favorite example here.
http://www.fieryrobot.com/blog/2010/07/10/a-watchdog-timer-in-gcd/

Combinations of some of the above, e.g, blocks (GCD) with notification

Leave a Reply