question about Xcode

Discussion in 'Mac Programming' started by Howiieque, Feb 6, 2009.

  1. Howiieque macrumors regular

    Feb 1, 2009
    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?
  2. kainjow Moderator emeritus


    Jun 15, 2000
    #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.

    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.

Share This Page