Objective-C about null values nil and null and nsnull

Source: Internet
Author: User
Tags define null

1. Nil

A null pointer pointing to an objective-C object

RepresentsObjectNull: nsstring * STR = nil; (# define nil (ID) 0 ))

2. Nil

A null pointer pointing to an objective-C Class Object.

RepresentsClassObjectNull: Class class = nil;

3. null

The objective-C value type is null: int number = NULL; (equivalent to int number = 0;) (# define null (void *) 0 ))

4. nsnull

A class definesSingleton objectUsed to indicate the null value in the collection object (nil value not allowed ).

#import <Foundation/NSObject.h>@interface NSNull : NSObject <NSCopying, NSCoding>+ (NSNull *)null;@end

[Nsnull null]; a singleton object is null.

5. Differences between nil and nsnull object message calls

If an object is equal to nil, no message is called and no exception is thrown;

If the object is of the nsnull type, an exception is thrown when a message is sent.

6. Note:

In objective-C, nsarray, nsdictionary, and nsset may all contain nsnull objects,

Therefore, if they contain nsnull objects, the program will crash.


Reference: http://blog.csdn.net/yhawaii/article/details/7442529



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