Pradeep Reddy Kypa
Pradeep Reddy Kypa

Reputation: 4022

Why is only UIKit.Framework imported in the header files? Why not the other default frameworks, e.g. Foundation framework?

I actually get confused some times about why we find only " #import " in all the header files that we create? And again why are we provided only 3 frameworks(Foundation, UIKit,CoreGraphics) when we create any iPhone Application?

Upvotes: 0

Views: 1876

Answers (2)

Amy Worrall
Amy Worrall

Reputation: 16337

UIKit requires Foundation, so it imports it itself. If you import UIKit, you get Foundation for free. Also, as Christoph says, your .pch causes all your files to import Foundation anyway.

In terms of being provided with three frameworks, you can link against whichever ones you like: look in the Target Settings for your app (top item on the left hand sidebar (named after your project), then click on your Target in the next column, then click the Build Phases tab):

Link with libraries section

Just click the Add button below the list, and you can choose whatever framework you want.

Upvotes: 3

Christoph
Christoph

Reputation: 1525

At least when starting a new project from xcode templates, the PreCompiled Headers (.pch) contains

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

so actually, no imports of those two would be required anywhere else.

I tend to drop

#import <UIKit/UIKit.h>

from all my source files and just keep the implicit one via the .pch file.

Upvotes: 2

Related Questions