I saw a lot of ObjC code that do:
obj = [[SomeObject alloc] init];
if (obj) {
}
but, as I understand it, the value inside () is logical, and 0 indicates that FALSE 1 indicates TRUE (there is another case in another language, which is 0 and 1 is false), and if the pointer does not indicate anything, it set to NULL (nil), which #defined is 0, so I think whether it is better to do this:
if (obj != nil) {
}
since it checks if obj is zero or not, no matter what the value is nil, so it does not rely on what nil(or NULL) is defined as 0?
source
share