This chapter focuses on the fundamentals of GUI application development. It covers the concepts of run loops, callbacks and delegation, user inputs, outlets, and display. Finally, these basic concepts are illustrated in an example application.
Figure 2-1 shows the simplified view that most users have when it comes to applications.
Figure 2-1. The way my mom sees herself using one of my applications
Figure 2-2. The details of a GUI app
If we give it a closer look, we will notice some key elements my mom takes for granted. My mom has a good perspective that we don’t need to disagree with. From her perspective, she is simply having an interaction with her computer. She opens the application, clicks, types, and sees a result right away. However, what’s going on under the covers is a bit more complex, as shown in Figure 2-2.
The first challenge is that we don’t want our code to execute and exit. We need our code to keep running to intercept my mom’s actions and react to them. We can’t pause or ask our code to sleep, because doing so might make us miss some events. Instead, we use what is called a run loop. Run loops are like threads that schedule work and coordinate the receipt of incoming events. By default, Cocoa applications have a main run loop that handles ...