O'Reilly logo

iOS 5 Programming Cookbook by Vandad Nahavandipoor

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 1. The Basics

1.0. Introduction

A lot has changed in iPhone, iPad, and iPod touch programming since the introduction of iOS 5. The whole runtime and the way we write Objective-C code has dramatically changed. ARC (Automatic Reference Counting) is now introduced into the LLVM Compiler, which in some ways gives us more flexibility and in other ways makes the runtime more fragile. In this chapter, we will get down and dirty with objects and how we can use them using the modern Objective-C runtime under ARC.

As the name of the language hints at, Objective-C is all about manipulating objects. These are containers for all the things you manipulate in the program, ranging from something simple like a point at the corner of a rectangle to entire windows containing all kinds of widgets Apple’s Cocoa libraries even define simple values such as integers as objects. Objects are defined according to classes, and therefore these two terms are commonly used interchangeably. But actually, a class is just a specification for defining objects; each object is said to be an instance of its class. Each class—and therefore the objects that are created from that class—is a set of properties, tasks, methods, enumerations, and much more. In an object-oriented programming language, classes can inherit from each other much like a person can inherit certain traits and characteristics from his parents.

Note

Objective-C does not allow multiple inheritance. Therefore, every class is the direct descendant of, at most, one other class.

The root class of most Objective-C objects is the NSObject class. This class manages the runtime capabilities offered by iOS; as a result, any class that directly or indirectly inherits from NSObject will inherit these capabilities as well. As we will see later in this chapter, objects that inherit from NSObject can take advantage of Objective-C’s distinctive memory management model.

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