PDA

View Full Version : newbie Help Question




WillieP
Feb 26, 2012, 07:26 PM
Im triyng to learn to code with Xcode

I got a book Beginning Objective C Programming - Tutorials for the Beginner
(http://www.amazon.com/gp/product/B006OGB8ZK/ref=kinw_myk_ro_title) and it has me starting out with doing a simple addition program. Mac os console

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init ];
// insert code here...
//declare and intialize variables


int firstNumber=2;
int secondNumber=3;
int totalSum=0;
firstNumber=firstNumber+1;
secondNumber=secondNumber+1;
totalSum=firstNumber+secondNumber;
NSLog(@"%d",totalSum);
NSLog(@"The program has terminated successfully.");
[pool drain];


return 0;
}

it returns the error that NSAutoreleasePool is unavailable.

I know what the program is attempting to do. its trying to output the result of 7 and that The program has terminated successfully in the console window.

any ideal why its resulting in this error and how I can fix it.



robvas
Feb 26, 2012, 07:50 PM
That looks like the old-style Autorelease code. Is that an old book?

Try doing it like this:
@autoreleasepool {
all your program
code goes here
}

WillieP
Feb 26, 2012, 07:54 PM
[pool drain];

It also told me that pool wasn't available and it asked if I meant powl. I deleted that and it built without an issue.

*edit
The book is a 2011 book and in the images for what to download for book compatibility it lists 4.2.1. Which is What I have. So no clue why it would be having me input code that is out of date. Unless he wasn't using the most current version when he tested stuff for the book if he did test things for the book.

thundersteele
Feb 26, 2012, 09:48 PM
Hmm, for $2.99 I wouldn't expect too much...