Possible Duplicate:
! vs == nil in objective-c
In Objective C, is there any difference between the following two co开发者_Go百科nditionals?
NSObject *obj;
if(!obj)
{
...
}
And:
NSObject *obj;
if(obj == nil)
{
...
}
Thanks! Just curious, figure it's a good thing to know.
There is no difference between the two forms.
!obj
also is valid when obj=NULL
or obj=@""
or empty Array etc. You get the point.
i.e. !obj
is more comprehensive since you seem to be using NSObject
& not any specific object type.
精彩评论