newbie Help Question

Discussion in 'Mac Programming' started by WillieP, Feb 26, 2012.

  1. WillieP, Feb 26, 2012
    Last edited by a moderator: Feb 26, 2012

    macrumors newbie

    Feb 26, 2012
    Im triyng to learn to code with Xcode

    I got a book Beginning Objective C Programming - Tutorials for the Beginner
    ( 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;
            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.
  2. macrumors 68000

    Mar 29, 2009
    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
  3. thread starter macrumors newbie

    Feb 26, 2012

    [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.

    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.
  4. macrumors 68030

    Oct 19, 2011
    Hmm, for $2.99 I wouldn't expect too much...

Share This Page