Trouble with Implementation Concept


#1

I don’t know if this has been covered in the book. If so, I missed it. At some point during the transition between command line tools and iOS programs, we went from executing the majority of our code in main to executing the majority of it in implementation blocks. I’m having a bit of a hard time understanding the concept of how implementation blocks are called. I understand that when defining methods, the method’s definition is executed when it is called in the delegate, for example, say to set an ivar or initialize an instance of the class the method belongs to. What I don’t understand is how so many of the methods defined in the implementation block are executed without ever being called outside of the implementation file.

Any help with this concept would be immensely appreciated.


#2

Programming in iOS is all event driven. That’s why you don’t see much code in main.m:

int main (int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain (argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

All your program has to do is respond to events.

Most events originate as a result of the user touching something on the screen. There are also events that originate as a result of the physical movement of the the device. There are more sources of events.

The important thing to know:

  • There is a message queue for events;
  • Messages containing information about the events enter this queue;
  • UIApplicationMain and its friends take the events out of the queue one by one send messages to the relevant objects. (Sending a message to an object means calling a method on that object.)

See: Definitive Discussion - Event Handling Guide for iOS


#3

Thank you! This is exactly what I needed to hear.