Whovian
Whovian

Reputation: 375

Objective C Hello World error

A lot of Objective-C tutorials seem to use the following program:

#import "Foundation/Foundation.h"

int main ()
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello world!");
    [pool drain];
    return 0;
}

I did take out all the stuff about the pools, and that worked fine. But this is giving me an error message. 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode. Maybe I did something wrong?

I'm using Xcode 4.3.2. I chose new project -> Command Line Tool -> Foundation. And this was the source code I used.

Upvotes: 2

Views: 428

Answers (2)

AmandaSai98b
AmandaSai98b

Reputation: 505

#import <Foundation/NSAutoreleasePool.h>

Upvotes: 0

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

This is because you are compiling with ARC, and this source is pre-ARC. If you change the compiler mode to disable ARC, it will compile fine. You could also use the new-style autorelease pool (works without ARC too):

#import "Foundation/Foundation.h"

int main ()
{
    @autoreleasepool {
        NSLog(@"Hello world!");
    }
    return 0;
}

Upvotes: 5

Related Questions