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

    Joined:
    Feb 26, 2012
    #1
    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.
     
  2. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
    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
        }
     
  3. thread starter macrumors newbie

    Joined:
    Feb 26, 2012
    #3
    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.
     
  4. macrumors 68030

    Joined:
    Oct 19, 2011
    Location:
    Switzerland

Share This Page