O'Reilly logo

Beginning iPhone® SDK Programming with Objective-C® by Wei-Meng Lee

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

Appendix D. Crash Course in Objective-C

Objective-C is an object-oriented programming language used by Apple primarily for programming Mac OS X and iPhone applications. It is an extension to the standard ANSI C language and hence it should be an easy language to pick up if you are already familiar with the C programming language. This appendix assumes that you already have some background in C programming and focuses on the object-oriented aspects of the language. If you are coming from a Java or .NET background, many of the concepts should be familiar to you; you just have to understand the syntax of Objective-C and in particular pay attention to the section on memory management.

Objective-C source code files are contained in two types of files:

  • .h — header files

  • .m — implementation files

For the discussions that follow, assume that you have created a View-based Application project using Xcode and added an empty class named SomeClass to your project.

DIRECTIVES

If you observe the content of the SomeClass.h file, you will notice that at the top of the file is an #import statement:

#import <Foundation/Foundation.h>

@interface SomeClass : NSObject {

}

@end

The #import statement is known as a preprocessor directive. In C and C++, you use the #include preprocessor directive to include a file's content with the current source. In Objective-C, you use the #import statement to do the same, except that the compiler ensures that the file is included at most only once. To import a header file from ...

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