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

How do you create a variable of type "id"?

I thought variable types includes array, dictionary, float, etc. and that "id" was used in the "for" method. How do I declare a variable w/ type being "id"???

4 Answers

Stone Preston
Stone Preston
42,016 Points

id thing = nil;

you dont use the * since variables of type id are already pointers.

William Baker
William Baker
2,485 Points

It is the same as the other types, so just replace where you would put an int or float with id.

I tried "id *thing = @"nil"" but it doesn't work.. Still a bit confused.

William Baker
William Baker
2,485 Points

You are setting the NSString "Nil". What you need to do is set nothing or = nil;

*Listen to Stone :)

Thanks guys, help was appreciated.