Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Initializing with NSNumber

Having this declared:

NSNumber *mike;

Does this..

mike = [[NSNumber alloc] initWithInt: 23];

do the same thing(alloc and init) as this?

mike = @23;

2 Answers

Right on! That was perfect, nice documentation. Thank you!!!

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Waldo,

You are correct in that setting the mike variable to a number literal, such as @23 in this case, will call [[NSNumber alloc] initWithInt:23]. You can read more about Objective-C literals here.

I hope this helps.

Objects created through literal syntax are autoreleased.