Basics of Event-Driven Programming for iOS Apps

By Rajiv Ramnath

In iOS development most applications with highly interactive (or rich) user interfaces implement a programming model known as event-driven programming. Programs that primarily do computations and calculations in order to accomplish a task have a main function that orchestrates these computations and calculations.

Event-driven programs are different. Their purpose isn’t to accomplish a computational goal but to make a buffet of capabilities available to the user or external systems, and then react to these events.

Rather than orchestrating computations, therefore, the main function in event-driven programs runs event loops. The event loop catches events as they’re posted from external sources and processes them by handing them off to appropriate objects, which results in the correct methods in these objects being called.

User-interface events are generated by devices that interface with the operating system — such as a mouse or touchscreen — to enable human interaction with the application.

Event-driven programming isn’t just about dealing with user interaction. Sensors also post events that your program may need to handle. Other components of the system can also post events, such as the component that monitors the battery level