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.

General Discussion

Basic question

I was reading the forum and have some questions about what some vocal means.

In the following line of code can someone break it down to me and tell me what it means for 'thing' to be initialized to nil.

NSNumber thing = nil;

thanks!

4 Answers

Stone Preston
Stone Preston
42,016 Points

nil is just a zero pointer value

so when would you ever use that when coding?

Stone Preston
Stone Preston
42,016 Points

well, all objects start out as nil before you give them a value, so you see it used in init methods. You also use it when you dont want an object to have a value you anymore.

someObject = nil;

You can also use it to check if an object actually has a value (if you only wanted to do something if that object wasnt empty)

if (someObject != nil)

there are many uses but these are probably the most common

Thanks!