Chapter 2. Learning Objective-C

 

This chapter covers

  • Introducing Objective-C
  • Using messages
  • Implementing classes
  • Setting properties
  • Learning categories and protocols

In this chapter, we’ll examine all of the Objective-C elements that are applicable to iOS development. We assume that you have a good understanding of a rigorous programming language (like C), that you know the basic concepts behind object-oriented programming (OOP), and that you understand what the Model-View-Controller (MVC) architectural model is.

We’re now ready to move into the world of SDK development. We’ll take a quick tour to examine the programming language and frameworks you’ll be using when you program with the SDK.

2.1. Introducing Objective-C

All of the SDK’s programming is done in Objective-C, a full superset of C, allowing you to write any traditional C code. (There is also Objective-C++, which allows for full integration of Objective-C and C++, with some caveats.) It adds powerful object-oriented capabilities as well. These extensions come by way of the design philosophies of Smalltalk, one of the earliest object-oriented languages. Because of its origin beyond the standard boundaries of C, Objective-C’s messaging code may look a little strange to you at first. But after you get the hang of it, you’ll discover that it’s elegant and easy to read, providing some nice improvements over traditional ANSI C code.

2.2. The message

2.3. Class definition

2.4. Properties

2.5. The @ directive

2.6. Categories and protocols

2.7. Wrapping up Objective-C

2.8. Summary

sitemap