Alex Rivera | Logout

NSAutoreleasePool is unavailable

Asked 2011-07-11T20:04:17.077
32

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.

Edit
Report

2 Answers

19

Quick post just in case you still looking

You can disable ARC in build settings.

  • Click on you project, in the left hand organizer.
  • Select your target, in the next column over.
  • Select the Build Settings tab at the top.
  • Scroll down to "Objective-C Automatic Reference Counting" (it may be listed as "CLANG_ENABLE_OBJC_ARC" under the User-Defined settings group), (if you do not find ARC option under build settings, you might need to toggle you compiler. You can find it under build settings)
  • and set it to NO.
answered 2012-03-23T12:24:50.790
3

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.

answered 2011-12-06T15:32:54.680

Your Answer