srikanth rongali
srikanth rongali

Reputation: 1453

In Objective C where the predefined classes are stored?

In C if we include #stdio.h we get some functions like printf, scanf. In the same way for Objective C what we should do to include NSLog,NSArray,... and where the definitions of these NSLog, NSArray are stored ? Please clarify my confusion.

Upvotes: 0

Views: 310

Answers (3)

Nitesh
Nitesh

Reputation: 470

NSLog, NSArray and other basic classes are included in Framework.h file. To import all these classes in your program simply add

#import Framework\Framework.h and leave rest for the compiler.

Upvotes: 0

Yuji
Yuji

Reputation: 34185

Adding to what jib wrote: to use those functions, one puts a line

#import <Foundation/Foundation.h>

at the top of the source code. This corresponds to #include <stdio.h> in the standard C. In OS X,

#import <FirstPart/SecondPart.h>

reads the header file at FirstPart.framework somewhere in the framework search path (typically, /System/Library/Frameworks) and then the SecondPart.h is looked up inside FirstPart.framework/Headers/. So, in the case of #import <Foundation/Foundation.h>, the file is at /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h. Now, if you open that file, you see it just have lots of other #import's, as in :

#import <Foundation/NSObjCRuntime.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
....

and the real definitions are in those files. In general, you shouldn't import those individual headers, but should just import the main header (in this case Foundation/Foundation.h); the compiler has an optimization which makes it faster that way.

Upvotes: 4

unknown
unknown

Reputation:

NSLog and NSArray are both defined in Foundation.framework. In XCode cmd-click on a symbol to jump to a definition. You can add the enviroment variable DYLD_PRINT_LIBRARIES to your app to log Library loads on app launch.

Upvotes: 3

Related Questions