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
Ethan Bagley
5,044 PointsObjective-C Basics stage 5, task 3/4
I'm having trouble setting the planck value in this challenge. Here's the code so far:
NSNumber *foxtrot = [[NSNumber alloc] initWithInt:24]; NSLog(@"foxtrot %@", foxtrot);
NSNumber *planck = [[NSNumber alloc] initWithInt:6.626];
What am I doing wrong? Any help is appreciated!
5 Answers
Ethan Bagley
5,044 PointsHey Bradan,
This is the code that was accepted:
NSNumber *foxtrot = [[NSNumber alloc] initWithInt:24]; NSLog(@"foxtrot %@", foxtrot); NSNumber *planck = [NSNumber numberWithDouble:6.626];
Thank you for your guidance!
Bradan Jackson
20,558 PointsEthan,
It appears that you are trying to initialize "planck" with an integer. 6.626 is a floating number.
Regardless, in this challenge, it does not require you to alloc or init for "planck", so try dropping the square brackets and the alloc/init.
Hope this helps!
Bradan Jackson
20,558 PointsThat's strange. I got it with
NSNumber *planck = @6.626;
Glad you got it!
Ethan Bagley
5,044 PointsI've noticed a few spots where it wasn't necessary to use the exact code they were looking for, just to provide the correct output. I'm guessing that:
NSNumber *planck = [NSNumber numberWithDouble:6.626];
AND
NSNumber *planck = @6.626;
provide the same output?
Amit Bijlani
Treehouse Guest TeacherWhenever you use the @ symbol, it is a shortcut to creating an object. The @ symbol is an indicator to the compiler. When the compiler comes across it in your code it is then instructed to convert it to object allocation and initialization.
Here's what each NSNumber literal is analogous to:
// character literals.
NSNumber *theLetterZ = @'Z'; // equivalent to [NSNumber numberWithChar:'Z']
// integral literals.
NSNumber *fortyTwo = @42; // equivalent to [NSNumber numberWithInt:42]
NSNumber *fortyTwoUnsigned = @42U; // equivalent to [NSNumber numberWithUnsignedInt:42U]
NSNumber *fortyTwoLong = @42L; // equivalent to [NSNumber numberWithLong:42L]
NSNumber *fortyTwoLongLong = @42LL; // equivalent to [NSNumber numberWithLongLong:42LL]
// floating point literals.
NSNumber *piFloat = @3.141592654F; // equivalent to [NSNumber numberWithFloat:3.141592654F]
NSNumber *piDouble = @3.1415926535; // equivalent to [NSNumber numberWithDouble:3.1415926535]
// BOOL literals.
NSNumber *yesNumber = @YES; // equivalent to [NSNumber numberWithBool:YES];
NSNumber *noNumber = @NO; // equivalent to [NSNumber numberWithBool:NO];