Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

WillieP

macrumors newbie
Original poster
Feb 26, 2012
2
0
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
Code:
#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.
 
Last edited by a moderator:

robvas

macrumors 68040
Mar 29, 2009
3,240
629
USA
That looks like the old-style Autorelease code. Is that an old book?

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

WillieP

macrumors newbie
Original poster
Feb 26, 2012
2
0
re

[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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.