Xcode 5: Modules
A new compiler feature in Xcode 5 is modules. Modules simplify importing header files and linking frameworks. They also can build your project faster, working similarly to precompiled headers.
Prerequisites #
To use modules you must be using either the Mac OS X 10.9 SDK or the iOS 7 SDK. Modules do not work with earlier SDKs. Module support is currently limited to C and Objective-C code.
Build Settings #
Xcode has two build settings for modules. If you want to use modules in your Xcode project, you must set the Enable Modules (C and Objective C) build setting to Yes. Setting the Link Frameworks Automatically build setting to Yes keeps you from having to manually add frameworks to your Xcode project.
Importing Headers #
To import a framework’s header files, use the @import statement and supply the name of the framework. The following example imports the header files from the Cocoa framework:
@import Cocoa;
To import a single header file from a framework, add a period to the framework and supply the name of the header file. The following example imports the header file AudioHardware.h from the Core Audio framework:
@import CoreAudio.AudioHardware;
Currently you can use @import only with Apple’s frameworks.
Using Modules with Existing Import Code #
If you have existing code that uses #import or #include to include headers, you can support modules without changing your code. Set the Enable Modules build setting to Yes, and Xcode will use modules to build your project.