For those of you new to Objective-C, welcome on board! In this chapter, youll receive an introduction to the language and then dive right in by writing some code. Youll start with an overview of the Apple Objective-C development environment and discuss some of the reasons why Objective-C is such a popular language for application development. Next, you begin using Xcode, Apples integrated development environment (IDE), and see how it makes Objective-C programming both enjoyable and efficient.
Introduction
Objective-C is the primary programming language for developing applications on Apples OS X and iOS (iPod, iPhone, iPad) platforms. In recent years, these platforms have become some of the most popular application development environments. A key reason for this success is due, in fact, to features of the Objective-C language.
Apple released version 2.0 of Objective-C in 2007. It added many new features to the language, including declared and synthesized properties, dot notation, fast enumeration, exception support, runtime performance improvements, and 64-bit machine support.
The Objective-C language has continued to evolve and acquire features that make Objective-C programming more powerful and expressive. Some of the more significant recent additions to the language include automatic reference counting for Objective-C objects, improved support for data hiding, improved type safety for enumerations, as well as new language constructs for block objects, literals, and other features.
Apple Objective-C Platform
Apples Objective-C development environment consists of several parts:
Objective-C programming language
Objective-C runtime environment
Software libraries
Software development tools
Object-oriented software development using Objective-C is the main subject of this book. As such, Part 1 of this book covers the programming language and the way it supports object-oriented programming.
Objective-C programs execute within the Objective-C runtime environment; it enables the dynamic programming capabilities of the language. Part 2 of this book explores the Objective-C runtime environment in depth and demonstrates how to use its application programming interfaces (APIs).
The software libraries include a set of frameworks, libraries, and services that provide general-purpose functionality to simplify application development. This software provides, out-of-the-box, much of the functionality needed to develop applications on the OS X and iOS platforms. Part 3 of this book covers the Foundation Framework, the base APIs that are used for any type of Objective-C program.
Part 4 focuses on advanced features of Objective-C that are of particular interest to programmers as they develop more sophisticated applications.
The software development tools enable source code editing and compilation, user interface development, version control, project management, testing and debugging, and other features. They also simplify application development and enable developers to be more efficient when developing, managing, and maintaining Objective-C software. Throughout this book, instructions are provided for using these tools to develop programs. Appendix B offers additional tips and recommendations.
Why Objective-C?
So, what are the benefits of Objective-C compared to the many other programming languages available today? After all, quite a few languages support object-oriented programming. Is its being the primary programming language for developing applications on Apples OS X and iOS platforms the biggest reason for its popularity? Well, Objective-C is a great programming language on its own merits, with a variety of features that make it incredibly powerful, versatile, and easy to use for application development:
Object-oriented programming : The Objective-C programming language provides complete support for object-oriented programming (OOP), including capabilities such as object messaging, encapsulation, inheritance, polymorphism, and open recursion.
Object messaging : Object messaging enables objects to collaborate by passing messages between themselves. In effect, Objective-C code (e.g., a class/object method or a function) sends a message to a receiving object (the receiver) and the receiver uses the message to invoke its corresponding method, returning a result if required. If the receiver does not have a corresponding method, it can handle the message in other ways, such as forwarding it to another object, broadcasting it to other objects, introspecting it and applying custom logic, and so forth.
Dynamic runtime : Compared to many other languages that support OOP, Objective-C is very dynamic. It shifts much of the responsibility for type, message, and method resolution to the runtime, rather than compile or link time. These capabilities can be used to facilitate developing and updating programs both in real time, without the need to recompile and redeploy software, and over time, with minimal or no impact to the existing software.
Memory management : Objective-C provides a memory management capability, Automatic Reference Counting (ARC), which both simplifies application development and improves application performance. ARC is a compile-time technology that incorporates many of the benefits of traditional automatic memory management mechanisms (i.e., garbage collectors). However, compared to these traditional technologies, ARC provides better performance (memory management code is interleaved with your program code at compile time), however, and it doesnt introduce memory management-induced pauses into program execution.
Introspection and Reflection : The Objective-C language includes features that enable a program to query an object at runtime, provide information (its type, properties, and the methods it supports), and modify its structure and behavior. This enables a program to be modified during its lifetime of execution.
C language support : Objective-C is primarily an object-oriented extension to the C language. It constitutes a superset of C. This means that the raw power of C is available and that C libraries can be accessed directly.
Apple technologies : Apple provides a wealth of software libraries and tools for Objective-C application development. The development kits have frameworks and libraries that include the infrastructure, enabling you to focus on developing your application-specific logic. Xcode, Apples integrated development environment, provides all the tools youll need to develop great applications using Objective-C.
These are just some of the reasons why Objective-C continues to grow in popularity among developersand Im sure youll discover more as you continue through this book. OK, enough talk. Now lets use Xcode to take Objective-C out for a test drive and find out what its really capable of!