Start Developing iOS Apps Today is the perfect starting point for creating apps that run on iPad, iPhone, and iPod touch. View this guide’s four short modules as a gentle introduction to building your first app—including the tools you need and the major concepts and best practices that will ease your path.
The first three modules end with a tutorial, where you’ll implement what you’ve learned. At the end of the last tutorial, you’ll have created a simple to-do list app.
After you build your first app and before you start your next endeavor, read the fourth module. It explores the technologies and frameworks you might want to adopt.
Even though it takes you through every step of building a simple app, to benefit most from this guide, it helps to be acquainted with computer programming in general and with object-oriented programming in particular.
Get the Tools
Before you start developing great apps, set up a development environment to work in and make sure you have the right tools.
To develop iOS apps, you need:
A Mac computer running OS X 10.9.4 or later
Xcode (latest version)
Xcode is Apple’s integrated development environment (IDE). Xcode includes a source editor, a graphical user interface editor, and many other features. The iOS SDK extends Xcode to include the tools, compilers, and frameworks you need specifically for iOS development.
Download the latest version of Xcode on your Mac for free from the App Store. The iOS SDK is included with Xcode.
To download the latest version of Xcode
Open the App Store app on your Mac (by default it’s in the Dock).
In the search field in the top-right corner, type
Xcodeand press the Return key.
Click Free .
Xcode is downloaded into your
Review a Few Objective-C Concepts
As you write code in the tutorials, you’ll be working with the Objective-C programming language. Objective-C is built on top of the C programming language and provides object-oriented capabilities and a dynamic runtime. You get all of the familiar elements, such as primitive types (
float, and so on), structures, functions, pointers, and control flow constructs (
for statements). You also have access to the standard C library routines, such as those declared in
Objects Are Building Blocks for Apps
When you build an iOS app, most of your time is spent working with objects.
Objects package data with related behavior. An app is a large ecosystem of interconnected objects that communicate with each other to perform specific tasks, such as displaying a visual interface, responding to user input, and storing information. You use many different types of objects to build your app, ranging from interface elements, such as buttons and labels, to data objects, such as strings and arrays.
Classes Are Blueprints for Objects
A class describes the behavior and properties common to any particular type of object.
In the same way that multiple buildings constructed from the same blueprint are identical in structure, every instance of a class shares the same properties and behavior as all other instances of that class. You can write your own classes or use framework classes that have been defined for you.
You make an object by creating an instance of a particular class. You do this by allocating the object and initializing it with acceptable default values. When you allocate an object, you set aside enough memory for the object and set all instance variables to zero. Initialization sets an object’s initial state—that is, its instance variables and properties—to reasonable values and then returns the object. The purpose of initialization is to return a usable object. You need to both allocate and initialize an object to be able to use it.
A fundamental concept in Objective-C programming is class inheritance, the idea that a class inherits behaviors from a parent class. When one class inherits from another, the child—or subclass—inherits all the behavior and properties defined by the parent. The subclass can define its own additional behavior and properties or override the behavior of the parent. Thus you can extend the behaviors of a class without duplicating its existing behavior.
Objects Communicate Through Messages
Objects interact by sending each other messages at runtime. In Objective-C terms, one object sends a message to another object by calling a method on that object.
Although there are several ways to send messages between objects in Objective-C, by far the most common is the basic syntax that uses square brackets. If you have an object
somePerson of class
XYZPerson, you can send it the
sayHello message like this:
The reference on the left,
somePerson, is the receiver of the message. The message on the right,
sayHello, is the name of the method to call on that receiver. In other words, when the above line of code is executed,
somePerson will be sent the
Protocols Define Messaging Contracts
A protocol defines a set of behaviors that are expected of an object in a given situation. A protocol comes in the form of a programmatic interface, one that any class may implement. Using protocols, two classes distantly related by inheritance can communicate with each other to accomplish a certain goal, such as parsing XML code or copying an object.
Any class that can provide useful behavior to other classes can declare a programmatic interface for vending that behavior anonymously. Any other class can choose to adopt the protocol and implement one or more of the protocol’s methods, making use of the behavior.