The difference between nil,null,nil,nsnull in iOS

Source: Internet
Author: User
Tags null null

Recently the mood is not very good, often the mood is not very good when likes to learn something, writes something, specifically because what mood is not too fortunately here does not give everybody to explode the material!


1, Nil defines an instance as null, pointing to a null pointer to an object in OC.

Note: When you release an object and assign the object a value of nil, this ensures security.

2, NULL is commonly used in C language to represent a null value.

Note: In Objective-c, the nil object is designed to be associated with a NULL null pointer. The difference is that nil is an object, and null is just a value. And we're not going to generate crash or throw exceptions for the nil call method.

3. Nil is used to define an empty class

Example: Class SomeClass = Nil;

4. The Nsnull class defines a singleton object used to represent the null value of the collection object.

Note: The collection object cannot contain nil as its specific value, such as Nsarray, Nsset, and Nsdictionary. Accordingly, the nil value is represented by a specific object nsnull. Nsnull provides a single instance for representing the nil value in the object's properties. The default implementation method, Dictionarywithvaluesforkeys: And setvaluesforkeyswithdictionary: automatically converts nsnull and nil to each other, so your object does not require nsnull test operations .

The difference between nil,null,nil,nsnull in iOS

Related Article

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: 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.