Defining Classes in Your App

Before you can create objects in memory, you have to decide what they should do in your app. You can then add class definition files that define the features of your new objects.

This is a multi-stage process. Follow these steps:

1. Decide what you want the class to do. Sometimes this question has an obvious answer; all apps have an App Delegate and most have at least one View Controller, so most apps include these objects. Other objects, such as those for video and sound support and extended graphics, are optional, and you must find them and add them as needed. (Don’t forget that you can search online for sample code.)

2. Look through the documentation to find an existing iOS class that matches your needs.

genius_2c.eps

A useful timesaver is to look for sample code to see which objects Apple and other developers have used to add a feature. You can take these “recipes” and modify them. This is quicker than creating code from scratch.

note_2c.eps

The iOS kit-of-parts objects solve specific problems and add specific features such as styled text, video, Twitter support, and so on. If your app has some unique requirements—for example, if it’s an original game—it’s likely you’ll have to use the more generic data collection objects in iOS and build your own code around them. ...

Get iOS App Development Portable Genius 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.