Amazon.com Widgets Foundation Classes
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 02:56:50 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 15 - Numbers, Strings, and Collections
| | | |-+  Foundation Classes
Pages: [1]   Go Down
Print
Author Topic: Foundation Classes  (Read 488 times)
Keoeul
Newbie
*
Posts: 2


Email




« on: January 01, 2011, 12:42:50 PM »

I am working my way through chapter 15 and have a question.

Foundation classes, like NSNumber, are added to the autorelease pool, so its not necessary to manually release them unless you create one.

That being said, classes like NSNumber in the book examples don't have the standard alloc/init methods.

I assume that because they are foundation classes, they don't require alloc/init?

Thanks for the help in advance
Logged
TotalLuck
Full Member
***
Posts: 107



WWW Email




« Reply #1 on: January 01, 2011, 05:51:12 PM »

hi

you can use alloc/init methods with the NSNumber class. you have to remember to release them though. 

it is easier for me though to use the autorelease pool and let the program manage it for me.

so you can can do this:
Code: (Objective-C)
NSNumber *myNumber = [[NSNumber alloc] initWithInt: 69];
//use myNumber  in some way here

[myNumber release]; // make sure you release it when done



but when you do this, you don't have to release it, it will be autoreleased for you.
Code: (Objective-C)
NSNumber *myNumber = [NSNumber numberWithInt: 69]; // this is a creation and initialization class method for NSNumber class which ads it to the autorelease pool. 

// use myNumber in some way here

// forget about it! its auto released

make sure you reread chapter 15,  the first few pages  talk about this.   but if you have any more questions feel free to post .

Greg
Logged

Apps available on  iTunes store:
"ADACode"  iPhone and iPad versions, "ADAGuidelines" iPhone & iPad versions,  "Rehabilitation Act of 1973" for iPhone
"APokerTimer" now for iPhone http://bit.ly/h1fAJp
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.