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

B Mo
B Mo
1,703 Points

a little guidance for these quizzes would be helpful. how do i declare a variable of type id and set the value to nil?

i usually get the 1st question of the quizzes easily and have trouble with the 3rd question but this one i'm not getting the 1st question.

1 Answer

Nick Sint
Nick Sint
4,208 Points

Okay lets break the questions down

  1. The task is to declare an "id" variable called thing. Note that unlike other types, "id" does not require a pointer. Usually you declare a string using "NSString *string = ..." but for id you just type "id variableName = ...". Therefore the correct statement to use here is:
id thing = nil;
  1. The NSNumber literal syntax is simply @number (i.e. @4 or @7 or @100). Therefore to assign thing to an NSNumber of 4,
thing = @4;
  1. Just remember here that the syntax for outputting a id variable is %@.
NSLog(@"thing = %@",thing);