RandomPossessions FAILS from the get go


#1

hello all,

I have started the second chapter and failed from the start. i went through the first addition of this book and was very pleased. i hope after this small issue i will enjoy this book just as much.

After entering this code the book says to click the run button. the book seems to know more than i do because its app ran and mine didnt. :laughing: I have retyped everything verbatim out of the book twice now and cant seem to find anything wrong.

Code is cut and pasted below.

Why am i getting this error?
What can i do to fix it?
What can i do to prevent it?

please help

//
// main.m
// RandomPossessions
//
// Created by 1/26/12.
// Copyright Ā© 2012 Apple. All rights reserved.
//

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
// :imp: This is were the problem occurs. The error says ā€œNSAutoreleasePoolā€ is unavailable: not available in automatic counting mode (2)
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSMutableArray *items = [[NSMutableArray alloc] init];

[items addObject:@"One"];
[items addObject:@"Two"];
[items addObject:@"Three"];

[items insertObject:@"Zero" atIndex:0];

for(int i = 0; i < [items count]; i++) {
    NSLog(@"%@", [items objectAtIndex:i]);
}

// :imp: and the second error here "release" is unavailable: not available in automatic reference counting mode (2)
[items release];

//dont leave items pointing 
items = nil;

[pool drain];
return 0;

#2

Joey,

I had the same problem initially - but I got around it by disabling ā€˜Automatic Reference Countingā€™ when creating the new project. Basically, start a new project, choose terminal, then from the drop down box select ā€˜Foundationā€™ and uncheck the box for Automatic Reference Counting.

Once you do that - those functions NSAutoReleasePool and the pool drain message should work without error. You can write those in place of the '@autoreleasepool function (just delete that part and the brackets {} and write the code verbatim). I didnā€™t see any errors on my part after thatā€¦

Vijay


#3

Hereā€™s a screenshot I took just now - at the bottom you can see what the Log Navigator prints outā€¦

Hope this helps,

-Vijay