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

Dynamic Typing Code Challenge Unsolved :-(

Can anyone help me with this code challenge? https://teamtreehouse.com/library/dynamic-typing

It goes like this: "Declare a variable named "thing" of type 'id' and initialize it to 'nil'." This works in Xcode:objective-c id thing = @[@"nil"]; This works in Xcode:objective-c id thing = @"nil"; but when I submit it to the Code Challenge, it says:"Bummer! Did you declare the variable 'thing' and set it to 'nil'?"

What am I doing wrong and how should I solve this challenge?

3 Answers

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Matej, try using id without @ as it is already implicit.

Hi Matej, When you set it up as id thing = @"nil"; you actually defined |thing| as a string object with the value "nil" (i.e. the string, "nil") and not the actual nil value :)

id thing = @"nil" works on x-code because |id| can be passed any type of object; therefore, it is syntactically correct and will compile.

Thanks a lot! This worked: id thing = nil; btw, what does that @ stand for? what does it say? yup, I'm a beginner :-)

When someone answers your question and helps you resolve the problem, please choose a "Best Answer". This way, the person who gave you the answer gets extra points and it encourages participation.

Oh, and welcome to Treehouse. ;)

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Jessica, congrats for your new status as a moderator :-)

Thanks. ^_^;;