PDA

View Full Version : question about Xcode




Howiieque
Feb 6, 2009, 09:40 AM
i have a question about compile a programme, here is the code:

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

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

ABAddressBook * book = [ABAddressBook sharedAddressBook];
NSArray * people = [book people];

int count = [people count];
int i;
for (i = 0; i < count; i++) {
ABPerson * person = [people objectAtIndex:i];
NSString * firstName = [person valueForProperty:@"First"];
NSString * lastName = [person valueForProperty:@"Last"];
printf("%s %s\n",
[lastName UTF8String],
[firstName UTF8String]);
}

[pool drain];
return 0;
}

WHY i have to explicitly explicitly add AddressBook.framework to add to the project(from menu Project->Add to project)? i have already import it in my code.

if i deleted the line #import <Foundation/Foundation.h>, nothing happened, but without the line #import <AddressBook/AddressBook.h>, error occurred. WHY?



kainjow
Feb 6, 2009, 10:43 AM
WHY i have to explicitly explicitly add AddressBook.framework to add to the project(from menu Project->Add to project)? i have already import it in my code.
#importing/#including just reads in the header. You still need to link the framework/library with your application so it knows where those methods/functions come from.

if i deleted the line #import <Foundation/Foundation.h>, nothing happened, but without the line #import <AddressBook/AddressBook.h>, error occurred. WHY?
You might have a precompiled header in your project that already imports this framework (or the Cocoa framework) and so it's unnecessary to include again.