An Overview of the Objective-C Foundation Framework

From Techotopia
Jump to: navigation, search
PreviousTable of ContentsNext
Objective-C EnumeratorsWorking with String Objects in Objective-C

Purchase the full edition of this Objective-C book in Print ($14.99) or eBook ($12.99) format
Objective-C 2.0 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters.

Buy Print

In previous chapters of Objective-C 2.0 Essentials we have covered the concept of object-oriented programming in considerable detail. So far, however, we have focused almost exclusively on the how to create and work with our own classes and objects within Objective-C programs.

Now that we have a firm understanding of how to work with objects we can apply what we have learned to using a set of pre-existing classes that are provided with Objective-C to make our jobs as programmers much easier. These classes belong to the Foundation Framework.

The Foundation Framework

<google>IOSBOX</google> The Objective-C Foundation Framework is a essentially set of classes that are provided to speed and ease the process of developing applications using Objective-C. The framework was developed by NeXT Computer as part of the NeXTStep environment. When NeXT was acquired by Apple, Inc. the Foundation classes quickly became of basis of Mac OS X and then the iPhone development kit. For a full history of how this came to be, refer to the chapter entitled The History of Objective-C.

Due to the fact that the Foundation Framework started life of part of NeXTstep, the classes that comprise this framework all begin with the letters "NS".

You will recall that when we created our first class in An Overview of Objective-C Object Oriented Programming we derived our class from NSObject. NSObject is a part of the Foundation Framework and as you become more familiar with the framework you will learn that most Foundation classes are derived from this class. In this and subsequent chapters we will look in more detail at some of the other classes provided by the framework.

Including the Foundation Headers

In previous chapters we have been including the header files for the Foundation Framework in our examples. This is achieved using the following line of code:

#import <Foundation/Foundation.h>

In fact, if we don't want to have to worry about including the header file for each Foundation class we wish to use in a code file, this is all we need to do. Alternatively, we can selectively include the header files for only the classes we intend to use. For example, the following code imports only the headers we need:

#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
int main (int argc, const char * argv[])
{
    @autoreleasepool {
        NSString *myString = @"Hello";
    }
    return 0;
}

Finding the Foundation Framework Documentation

A detailed overview of every class and method in the Foundation Framework is beyond the scope of this book and would be largely redundant given that this information is already provided by Apple in various locations. Instead, this book will focus on teaching you how to use the most common Foundation classes to work with numbers, strings, arrays and file systems. This knowledge, combined with the Apple Foundation documentation should be all you need to be begin working proficiently with these classes.

The Foundation documentation may be accessed either via the Apple web site at:

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/ObjC_classic/

or from within the Xcode development environment (accessed via the Help->Documentation menu option and listed under Foundation Framework Reference). In addition, you can right click on a Foundation class name in the Xcode editor window and choose Find Selected Text in API Reference to find the documentation for that class. Alternatively, open the Help->Documentation window and enter the name of the class into the search text field.

The Framework Reference Documentation lists all the classes available and for each class describes in detail what the class does and what methods are available. In the following chapters we will look in detail at how to work with some of these classes.

Purchase the full edition of this Objective-C book in Print ($14.99) or eBook ($12.99) format
Objective-C 2.0 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters.

Buy Print



PreviousTable of ContentsNext
Objective-C EnumeratorsWorking with String Objects in Objective-C