Array of small details that cannot be clarified during iOS development -- array = nil and [array count] = 0, iosnil

Source: Internet
Author: User

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.