Hi. First of all, I would like to say that you’ve written one hell of a book. I’m a beginner in iOS programming with quite some experience with other technology stacks (mainly Java SE/EE and Python, but I’ve used a few other languages as well), and have read many programming books, and this one is just really nicely written.
What I’m struggling with is the delegate vs. taget/action vs. callbacks question. I don’t really get when you would use which. I managed to get formal / informal protocols out of the equation as informal ones seem not to be used any more - modern Objective-C uses @optional @protocol methods - correct?
At one point in the book you say that delegates are object-oriented version of callbacks. Why is that? For example, in Java, one would create an interface with a few methods and register it somehow (it would be multicast most of the time, though) - this is pretty much what the delegate is, right? So the Java implementations of the given interface are also objects, and the methods are callbacks, so I see no difference. Or by callbacks do you mean simple functions, like in functional programming? But then again, there are languages where functions are also objects and one can store arbitrary data in.
What I also fail to grasp is why and when I would use the target/action pattern, and when the delegate. As far as I can tell, UIButton events (touchUpInside and others) could be implemented using protocols - after all, this could be a protocol with a whole bunch of @optional methods, the view controller would conform to the protocol, and implement only the ones it needs. Then, it would set itself as the UIButton delegate, possibly for multiple buttons, no matter, because the methods could get the (id)sender. (As a side question, why is it id and not UIButton?) Why is it implemented with a bunch of type-unsafe selector to event mappings? Is it the way it always had been and stayed even after Objective-C 2.0 introduced @optional methods just for backwards-compatibility’s sake / not doing too much work updating all the classes?
The biggest question: when and why would I want to use target/action? I have written a few classes myself so far and I seriously always think of delegates, but maybe I need to change my approach?