Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
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:mad:"First"];
NSString * lastName = [person valueForProperty:mad:"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

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.