Chapter 5. Building a Project: A Four-Function Calculator
In this chapter, we’ll build a simple Calculator application with four functions: add, subtract, multiply, and divide. When we’re done, our Calculator will contain the menu and window shown in Figure 5-1. In the process of building the Calculator, we’ll learn about Interface Builder, connections, and some of the commonly used Cocoa Application Kit (AppKit) classes.
Figure 5-1. Calculator application window and menu bar
We’ve chosen to build a calculator as the first “real” application in this text for several reasons. First, calculators are familiar; we’ve all used one, and we sort of know how they work. (When creating an application, the first thing to understand is the problem you need to solve.) Second, calculators are useful. As programmers, we’re constantly having to do silly little things like add two numbers together or convert a number from decimal to hexadecimal (the hex part will be built in Chapter 7). It’s a tool that you can put to work after you build it.
More importantly, a calculator is a good starting point for budding Cocoa developers. In subsequent chapters, we’ll use the Calculator as an infrastructure for learning about Cocoa graphics, printing, multiple windows, file handling, and many other features.
Creating your own calculator puts you in charge of its design. After all, there are many kinds of calculators: ...
Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.