O'Reilly logo

MacRuby: The Definitive Guide by Matt Aimonetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Fundamentals

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.

The way my mom sees herself using one of my applications

Figure 2-1. The way my mom sees herself using one of my applications

The details of a GUI app

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.

Run Loops

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required