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 Objective-C Basics (Retired) Beyond the Basics Alloc and Init

With the NSNumber *fortytwo example shown, where is the pointer in the 2nd line?

The example in the video shown is this:

NSNumber *fortyTwo = @42;

// equal to

[NSNumber numberWithInt:42];

I'm unclear on where the *fortytwo pointer is in the second line of code. What am I missing?

(For reference, these lines are listed in the iOS track : Objective-C : Beyond the Basics section : 'Alloc & init' video, 'Literals - shorthand notation')

4 Answers

I think you're right, it's a bit unclear: In the first line you declare a variable fortyTwo which is a pointer to an NSNumber and you allocate and initialize it with a value of 42, in the second line you call an initializer of NSNumber but there's no assigning to a variable. So i think it has to be: NSNumber *fortyTwo = [NSNumber numberWithInt:42]

Thank you Jeroen - that makes a lot more sense the way you've rewritten it! =)

Thank you! I had the same question!

Hi Massimo, I believe @ is a shorthand for a method of NSNumber that assigns the value of an int to an NSNumber object where fortyTwo points to. Grtz, Jeroen