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) Foundation Framework NSNumber

Roberta Voulon
Roberta Voulon
5,792 Points

NSNumber *planck;

Hello! I can't seem to see what's wrong with this... The error says to make sure to assign the correct value, which is 6.626...

// NSNumber *planck = [NSNumber numberWithFloat:6.626];

5 Answers

Not sure why it isn't working, but this will work.

NSNumber *planck = @6.626;

It's shorter, cleaner, and elegant. It basically does all the initialization work for you, you just have to include the '@' symbol.

Michael Hulet
Michael Hulet
47,912 Points

That line won't compile, because you forgot the semicolon

Whoops! Edited, thanks ;)

Roberta Voulon
Roberta Voulon
5,792 Points

well yeah I know that... but that's exactly how I did the foxtrot question right before, I assumed I had to do something different this time... bit silly I think to ask twice for the same answer, and then say it's wrong when I use the alternative class method exactly like in the video.

Roberta Voulon
Roberta Voulon
5,792 Points

I think I will log it as a bug, thanks a lot Joseph for the quick reply!

No problem! Yeah I tried to initialize foxtrot using a message call too, it worked there. Probably a bug in the challenge. In a way it's good, it encourages smaller and more readable code.

Michael Hulet
Michael Hulet
47,912 Points

If you're trying to run that exact code, it won't work, because of the // at the beginning of the line. That character marks that everything after it on the line is a comment, so the compiler ignores anything to that character's right, so the code you posted will never run. For future reference, though, I find the shorthand syntax easier:

NSNumber *planck = @6.626;
Roberta Voulon
Roberta Voulon
5,792 Points

I just added the // quickly in my post because the forum deleted the code, so I pasted the code back in and commented it out so it would pass. too lazy to check out what the proper tags are so it will parse :) I still think my original answer should have been accepted because in the video this was demonstrated as an alternative way, and I thought that's what they wanted me to do since the previous answer was already using the literal assignment (@syntax)