Home > Articles > Mobile Application Development & Programming

  • Print
  • + Share This
This chapter is from the book

Importing and Using Declarations in Files

A compiler instruction that you have seen in many of the code snippets in this hour is import. It is broadly similar to the C include statement but bypasses some of the issues that arise with multiple uses of the include statement. In Objective-C, import checks to see if the file has already been imported and does not repeat the import if it is unnecessary. Files within your project are identified by their filenames enclosed in quotes; files that are part of the frameworks are enclosed in < and >.

Typically, an interface (.h) file imports other interface files. An implementation file (.m) imports it own interface file, and it might import other interface files (usually not implementation files).

In an interface file, it is common to declare protocols and classes that will be defined later in the build process. Thus, instead of using

#import "myclass.h"

you might be better off simply declaring

@class myclass

The templates and samples demonstrate this style in many cases.

  • + Share This
  • 🔖 Save To Your Account