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) Advanced Objective-C Dynamic Typing

Dynamic Type

Video didn't show all of the needed codes for Dynamic Type. Can't figure out the Challenge Task. Need the codes for Shape.h

8 Answers

Charlie O'Shea
Charlie O'Shea
18,737 Points

I don't think part 2 was ever explained in the preceding video.

Plus it's hard to follow along when files suddenly appear in the navigation that we haven't got.

Stone Preston
Stone Preston
42,016 Points

what task of the challenge are you on? what code have you tried so far?

Challenge task 1 of 3 Declare a variable named thing of type id and initialize it to nil.

Stone Preston
Stone Preston
42,016 Points

declaring a variable of type id generally looks like:

id variableName = value;

note that since id types are pointers by default, you dont use an asterix like you would regular object variables.

so to declare an id type named thing and initialize it to nil you would use:

id thing = nil;

Got that part. It's the next 2 steps that's driving me nuts

Challenge task 2 of 3 Assign an NSNumber literal with a value of '4' to the variable 'thing'.

Stone Preston
Stone Preston
42,016 Points

you assign values to id object the same as any other. to assign a literal NSNumber you use literal syntax like so: someVariable = @x where x is the number value you want to assign.

to assign a literal value of 4 to thing you would use:

thing = @4;

Wow! Thanks. How bout the last one? Here's what I got...

NSLog(@"thing = 4", thing);

It's saying that I got the string right but the format was wrong

Stone Preston
Stone Preston
42,016 Points

you almost have it. you need to use a format specifier in place of the 4. use the %@ format specifier for object types:

NSLog(@"thing = %@", thing);

Yeah, you should put the "do this" in the actual tutorial. Also, the shape.h and shape.m files are not anything I'd built leading up to this point...