2
votes

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.

2
Forget this code if you use ARC ;) - MJB
The project's main.m template should have the correct version of this code already. Did you change it? - jscs

2 Answers

5
votes

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;
}
0
votes
#import <Foundation/NSAutoreleasePool.h>