IOS Study Notes 8-nil, Nil, null, NSNULL differences and usage

Source: Internet
Author: User

1. nil: Generally, it is assigned to an empty object;

2. NULL: It is generally assigned to NULL values other than nil. Such as SEL;

Give me a chestnut (so heavy ~) :

[NSApp beginSheet: sheet
ModalForWindow: mainWindow

ModalDelegate: nil // pointing to an object

DidEndSelector: NULL // pointing to a non object/class

ContextInfo: NULL]; // pointing to a non object/class

3. NSNULL: NSNull has only one method: + (NSNull *) null;

[NSNull null] is used to add a non-nil (indicating the end of the list) null value to NSArray and NSDictionary. [NSNull null] is an object, which is used when nil cannot be used.


4. When a message is sent to nil, NO is returned and NO exception is thrown. The program continues to run;

An exception is thrown when a message is sent to an NSNull object.


Because nil in NSArray and NSDictionary has a special meaning (indicating the end of the list), the nil value cannot be placed in the set. To store a value indicating "nothing", you can use the NSNull class. There is only one NSNull method:

+ (NSNull *) null;

 

Nil is an object pointer with NULL values, Nil is a class pointer with NULL values, and NULL is a basic data type with NULL values. These can be understood as the difference between nil, Nil, and NULL.

 

 

 

 

 

 

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.