Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
kasaltrix
9,491 PointsConfusion between Foundation and UIKit Frameworks
This question might sound silly because I am a beginner in iOS Development.
I wanted to ask that how can we use the classes found in the Foundation framework such as NSArray or NSString within an iOS project file even though we do not import Foundation/Foundation.h anywhere in our project.
On the other hand if I make a custom class in an iOS project inheriting from the NSObject using the File>NewFile option and want to use a UIKit Framework class, I have to import the UIKit/UIKit.h header file in that given project file.
1 Answer
Dylan Shine
17,565 PointsI believe when you create a new Cocoa Touch Class, Foundation is imported in the background by default. UIKit on the other hand isn't used to build all projects, such as command line applications, so they require you to import it manually on files that don't. If I create a new Cocoa Touch Class that inherits from NSObjects, I won't get UIKit, but if it inherits from something like UIViewController than it will...Xcode is just smart in that way.
kasaltrix
9,491 Pointskasaltrix
9,491 PointsThanks for your reply Dylan.
I googled some answers for my question and found that the .pch file was responsible for importing both these frameworks. But those articles were pretty outdated and I cannot find the .pch file under the supporting files folder in my iOS project.
I presume that what you are saying is correct but I am still confused!