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

Rodrigo Chousal
Rodrigo Chousal
16,009 Points

What's wrong here?

Instructions: Declare another variable named 'planck' of type NSNumber and assign it the value 6.626.

My Code:

NSNumber *foxtrot;
foxtrot = [ [NSNumber alloc] initWithInt: 24];
NSLog (@"foxtrot %@", foxtrot);
NSNumber *planck;
planck = [ [NSNumber alloc] initWithInt: 6.626];

3 Answers

Stone Preston
Stone Preston
42,016 Points
initWithInt: 6.626]

6.626 is not an int, its a float

Rodrigo Chousal
Rodrigo Chousal
16,009 Points

Oh, so should I write initWithFloat?

Stone Preston
Stone Preston
42,016 Points

yeah try that. you could also use an NSNumber literal as well.

NSNumber myNumber = @1.5;
Rodrigo Chousal
Rodrigo Chousal
16,009 Points

What about this?

Instructions:

Declare a third NSString variable named 'favorite' and assign a concatenated string to it by appending the variable named 'color' to the variable named 'preference'. (Remember to use the method 'stringByAppendingString').

My Code:

NSString *color = @"Purple";
NSString *preference = @"My favorite color is ";
NSString *favorite = [[preference stringByAppendingString : color]];
Stone Preston
Stone Preston
42,016 Points

NSString *favorite = [[preference stringByAppendingString : color]];

you have too many brackets around the method call. Try

NSString *favorite = [preference stringByAppendingString:color];
Rodrigo Chousal
Rodrigo Chousal
16,009 Points

You are the best. Thank you!