开发者

Checking for a nil value [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜