Reputation: 321
I am following "Programming in Objective-C" 3rd edition and I am having problems with the first example.
I keep getting this error:
Semantic Issue: 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode
Here is my code:
//
// main.m
// prog1 //
// Created by Steve Kochan on 1/30/11.
// Copyright 2011 ClassroomM, Inc.. All rights reserved. //
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Programming is fun!");
[pool drain];
return 0;
}
Any insight will be greatly appreciated.
Upvotes: 32
Views: 41213
Reputation: 2789
In my case, I wanted ARC on, and wanted to update a sample project to work properly. Apple's NSAutoReleasePool docs are technically correct, but don't come straight out and explain this. Here's how:
Take your application main, which probably looks something like this:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([DemoAppDelegate class]));
[pool release];
return retVal;
}
And change it to look like this:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([DemoAppDelegate class]));
}
}
Upvotes: 5
Reputation: 47
ARC is enabled when you first create a new project. Right know the only way I know how to enable or not enable it is when you first create your program. It is one of the checkboxes you have to unselect.
Upvotes: -1
Reputation: 19344
Quick post just in case you still looking
You can disable ARC in build settings.
Upvotes: 19
Reputation: 31
Here is a link to Apple's transition guide to ARC.
OK...check this out. Specific change to NSAutoreleasePool - this is how Xcode initializes itself when you create your first app. I don't know about you, but I love this idea!
No worries if you are following along w/ Kochan's book. When starting your project, just uncheck the "Use ARC" box. Everything will work.
Upvotes: 3
Reputation: 162712
The compiler is being asked to compile the file with ARC (automatic reference counting) enabled. Turn that off or, better yet, modernize your example:
int main (int argc, const char * argv[]) {
@autoreleasepool {
NSLog (@"Programming is fun!");
}
return 0;
}
(No, I can't tell you how, specifically, to turn off ARC, if that was the route you were to go down due to the aforementioned NDA.)
Upvotes: 43