Chapter 3. Interlude: Syntax

image with no caption

It’s time to get into some details. You’ve written a couple apps and gotten some of the big picture stuff sorted out. Now it’s time to get into some line by line details. Why are there @ symbols everywhere? What’s the difference between a method and a message? What exactly do properties do? It’s time to take a quick dive into the syntax of Objective-C; then we can get back into building apps.

Classes: Interface and Implementation

In Objective-C, a class is split into separate files, the .h and .m files. The .h file defines how other objects should interact with your class. It defines the properties, methods, and other attributes.

The .m file, which imports the .h, implements the internal behavior of your class. The compiler will check to make sure what is defined in your interface file has an implementation in the .m.

image with no caption

Header files describe the interface to your class

In Objective-C, classes are defined with interfaces in the header file. It’s where you declare whether your class inherits from anything, as well as your class’s instance variables, properties, and methods.

As Objective-C matured, more code has been moved into the implementation file as a class extension. This is the only way to define truly “private” properties and methods.

Get Head First iPhone and iPad Development, 3rd Edition 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.