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 trialB Mo
1,703 Pointsa 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
4,208 PointsOkay lets break the questions down
- 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;
- 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;
- Just remember here that the syntax for outputting a id variable is %@.
NSLog(@"thing = %@",thing);