Nil and nil and null judgments

Source: Internet
Author: User
, nil and nil and null judgments

During the development process, we return JSON data in the background via HTTP requests, and sometimes the value of a field in the data is null~, and then we assign this value to Nsarray,nsdictionary, or nsstring, and then we will determine if this value is null, the processing , and usually we will write when the inertial thinking is judged: if (dict = = nil) or if (dict = = nil) or if (dict = = NULL) or if (dict isequal nil), we find that it is not good to use, Did not play the role of judgment ~ later I found that the original can not be judged.

Simply put, it is when the dictionary, the array is null, the output of the background print is this:


Then, we need to use [NSNull NULL] to judge the code, as follows:


Isequal:[nsnull NULL] It was done, and Nsarray was the same.


Console printing: str= (null) means that a string or array or dictionary is a null pointer, rather than an empty string, that is used directly when judging:

The IF (str = = nil) is available. As shown in the following:



While the console prints: str = <NULL>, which represents an empty string, the assignment is null, the pointer is present, but the content is empty, this judgment needs to be used:

if (str is equal [NSNull null]), because on iOS, the content is empty can not be easily judged str==null (null on iOS [NSNull null])


In general, this is the case, the server is null, directly return the @ "null" string, so in iOS bad judgment, it is best to communicate with the background, if you encounter a null value, return @ "", to make a judgment

Nil and nil and null judgments

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.