Objective-C: Why should one check for != nil

前端 未结 4 1174
遇见更好的自我
遇见更好的自我 2020-12-20 01:31

I often see code like this:

// Approach 1
if(data != nil){
    // Do this and that
}

When one could simply do the check like this:

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 02:27

    This is mostly a style preference, or some people does not know that it is possible to use first solution.

    Moreover, they are languages like java where you can't write the second solution, You must write yourVar != null

提交回复
热议问题