OC Nil, Nil, NULL, NSNull, class, class

Source: Internet
Author: User

It was confusing, but after reading a lot of articles on the Internet, I had a slight gain.

1. Class and Class

Class refers to classes, which are types of objects (object). For example NSString *str = [[NSString alloc]init]; NSString is a class, which is the type of the object str.

Class refers to the type of classes, such as: Class AClass = [NSString class]; AClass is a class, nsstring this class, and class lying aclass type.

2, nil, nil, NSNull, NULL

Nil is a pointer to an object that becomes empty, such as nsstring *str = nil, for the object

Nil is a pointer to a class that becomes empty, such as class AClass = Nil

Nsnull is a class, a class that represents a null value. You can create an empty object with the class method + (NSNull *) null. Generally used for objects with null values in the collection

Nil cannot be stored in the Foundation collection because nil is used as a flag to end the set.

Nsarray *array = [Nsarray arraywithobjects:@ "one", @ "one", nil];

Use of Errors

Nsmutabledictionary *dict = [Nsmutabledictionary dictionary];

[Dict setobject:nil forkey:@ "Somekey"];

The right use

Nsmutabledictionary *dict = [Nsmutabledictionary dictionary];

[Dict setobject:[nsnull null] forkey:@ "Somekey"];

Null is to let the pointer to type C become empty, such as int *a = NULL;

Thanks for the guidance of this article http://www.3lian.com/edu/2015/06-09/220517.html

OC Nil, Nil, NULL, NSNull, class, class

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.