Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!