Importing Libraries

Libraries in C are split into two files, the interface, or header file (.h) and implementation (.m). The header tells the user what functionality is provided by the library. The implementation has the actual code. In this way it is easy to provide users with the interface files, and then give them a binary version of the library such that you can keep the implementation private.

Frameworks

Frameworks are a concept unique to OS X and iOS. Frameworks are folders that group together headers, binaries, and documentation for easy distribution. To see the various frameworks on your system, open /System/Library/Frameworks from the Finder. Despite looking like little legos, these are really just folders that you can double click on and look inside. In the Hello World program, we imported the Fondation framework with the line
@import Foundation;

System Libraries

System libraries are functionality that is outside of the C language defintion but are considered part of the standard language library. While much of the functionality of the C standard library will be superceeded by iOS frameworks, we do occasionally need to use the C standard librarys, for example the math library.
#import <math.h>
Commands that start with the '#' character are known as preprocessor directives. There are many of these, but #import is the most common one we will use. The angle brackets are what specify that this is a system library.

Custom Libraries

Custom libraries are code that we develop and want to reuse. They are included almost identically to ystem libraries:
#import "console.h"
Note the quotation marks. This means that the compiler will look for console.h in local paths.

Exercises

console.h console.m
  1. Import the math.h library. Write a program that will print out the sin of a number
  2. Download the console.h and console.m files. Add them to your project and import console.h. Update your sin taking program to use user input