开发者

Checking for a nil value [duplicate]

开发者 https://www.devze.com 2023-03-27 06:37 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: ! vs == nil in objective-c
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

精彩评论

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