I always wondered if NULL got toll-free bridged to nil. I figured that NULL is a pointer value of all zeroes and nil is actually a pointer to a special object. So my hypothesis was they weren’t interchangeable. I was wrong.
// Check to see what happens to a toll-free bridged ptr when it gets set to NULL. CFStringRef stringRef = NULL; NSString *str = (NSString *) stringRef; if (str == nil) { NSLog(@"str is nil"); } else { NSLog(@"str is NOT nil!!!"); } NSLog(@"The object value of nil is %@", nil); NSLog(@"The numeric value of nil is %d", nil);
Yields the following output:
2009-12-04 10:51:58.532 TollFreeBridging[18053:a0f] str is nil 2009-12-04 10:51:58.535 TollFreeBridging[18053:a0f] The object value of nil is (null) 2009-12-04 10:51:58.536 TollFreeBridging[18053:a0f] The numeric value of nil is 0
And then there’s NSNull….