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

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. ^_^;;