Array of small details that cannot be clarified during iOS development -- array = nil and [array count] = 0, iosnil
In many cases, our developers tend to be familiar with some difficult technical points, but they are always confused about some details or problems that are relatively simple, and array judgment is the first to bear the brunt.
Data is required during development. However, most of the data sent from the server is in JSon format, and an array exists. Therefore, some arrays do not contain elements in the development, at this time, we will be used to judge whether it is null. For example:
However, we will find that this does not work. If it is null, this error will be reported:
If we change it, it will be OK. How can we change it to arr. count during judgment! = 0, which means that the number of elements in the array is 0. To put it bluntly, the array is not empty. In this way, the results can be judged. Then, arr! = Nil and arr. count! What is the difference between = 0 and I think it is as follows: array = nil and [array count] = 0. when the former is true, it indicates that the object is nil, is a null pointer. If the latter is true, this array does not have any elements. Therefore, it is best to use [array count] to judge whether the array is null. = 0. I have a simple understanding of the above, and I hope you can add some suggestions.