Many times we developers tend to be relatively familiar with some of the more difficult technical points, while some of the details or the feeling of simple problems are always unclear, and the array of judgment is the first.
When we do development, we need data, but many times the data from the server is JSon format, there will be an array of the existence, then there will be a part of the development of the array of elements, this time, we will be accustomed to use is not empty to judge. For example:
but we will find that it does not work, such errors are reported when they are empty:
If we change it, we'll ok . How to change, is in the judgment of the time to change to arr.count!=0 , which means that the array of elements in the number of parts 0 , that is, the array is not empty, so that can play a judgment effect, then arr!=nil What is the difference between and arr.count!=0 , that you think you are plain to understand: array = = Nil and [array count] = = 0 , the former is Span style= "Font-family:menlo" >true indicates that the object is nil , which is an empty pointer. The latter is true indicates that the array does not have any elements, so it is best to determine if the array is empty [ Array Count] ! = 0 , the above when their own simple understanding, there is not the right place, but also hope you add.
An array of small details that are unclear in iOS development--array = = nil and [array count] = = 0 Difference