Cover by Alasdair Allan

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Building a Model

At this point, you should have a working UITableView. So far, you’ve implemented both the view and the controller parts of the MVC pattern. Now we’re going to return to Xcode and implement the model. This needs to be separate from the view and the view controller, since we want to decouple the way the data is stored from the way it is displayed as much as possible. This will increase the reusability of both the classes that handle the UI and the classes that store the data behind the scenes, allowing us to change how parts of the application work while affecting as little code as possible.

Right-click on the Classes folder in the Groups & Files pane and select AddNew File. When you see the New File window shown in Figure 5-9, make sure Cocoa Touch Class is selected on the left side of the screen. Next, select “Objective-C class,” make sure Subclass of NSObject is specified, and click on Next.

The New File window, which allows you to select the template Xcode will use to generate the new class interface and implementation file

Figure 5-9. The New File window, which allows you to select the template Xcode will use to generate the new class interface and implementation file

You will then be asked for the filename of the new class. Type in City.m and click on Finish. Xcode will generate a pair of files, City.h and City.m, containing the template interface and the implementation of the new class, and will put them in the Classes folder. If you look at these files, you can see that since you specified that ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required