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

what is a "nil" ?

also how do i make a function return one

2 Answers

When you declare a pointer, you can set it equal to the memory address of some object (like NSString).

nil is an empty value bound with an object memory address variable (the id type in objective c). nil has got no reference/address, just an empty value.

just type return nil; (nil is can replace any type id location, anything with a Asterix is type id)

When you declare a variable or constant, it might not exist. For example, if you are downloading some content from the internet, you are not sure whether you are able to get the data or not. So you might want to declare your variable as an optional because it is possible that you will get nothing (Poor internet connections, not internet connections, server errors, etc. might cause you to get nothing when you are downloading data from the internet). However, if you do get something in an optional, you won't get its value directly. Instead, if you print it to the console, it will show "some(a value)", and you have to unwrap it to get its full value. If there is actually nothing in there, you will get nill, which stands for nothing. So in an optional, there is either some value, or nil. But if you are not dealing with an optional, you don't have to consider about does the value in that variable or constant exist or not.