An array of small details that are unclear in iOS development--array = = nil and [array count] = = 0 Difference

Source: Internet
Author: User

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

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.