
1

object == nil or nil == object
source link: https://fann.im/blog/2012/06/25/object-equals-equals-nil-or-nil-equals-equals-object/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

object == nil or nil == object
Jun 25, 2012
在 Objective-C 中拿到一个对象后检查对象是否为空,一般有两种写法
if (object == nil) {
//...
}
if (nil == object) {
//...
}
这两种写法其实没有任何区别,从代码的可读性上来说第一种 object == nil
方式会好一点。但是推荐用第二种 nil == object
方式,最大的好处就是如果由于笔误 ==
写成了 =
,编译器会直接报错处理。而 object = nil
不会报错,一旦笔误写成了 object = nil
是很难 debug 查找问题。
via object == nil or nil == object to check whether an object is nil?
Was this page helpful?
</article
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK