I was reading a question asked about the difference between NULL and nil in objective-c, found here: NULL vs nil in Objective-C
I'm not sure if understood the difference completely. I understood that NULL should be use for C-style pointers and nil for id and object pointers.
I've been reading "Programming in Objective-C Fourth Edition" by Stephen Kochan. Some of the of the code samples in the book go against what was described in the question above.
For example:
One code sample creates a method that returns an NSMUtableArray where he tries to populate an NSMutableArray, if the Array is empty in the end he returns nil:
-(NSMutableArray *) someMethod
{
NSMutableArray *arr = [NSMutableArray array];
//try to populate arr
if([arr count])
{
return arr;
}
else
{
return nil;
}
}
Later on in a different code sample, he uses NULL for a pointer object
{
NSFileManager *fm = [NSFileManager defaultManager];
[fm copyItemAtPath: @"some file path" error: NULL]
}
Looking the NSFileManager documentation, it says to pass in nil for the NSError pointer if error information isn't wanted.