IOS int Nsinteger NSNumber differentiate

Source: Internet
Author: User

1.NSNumber is a class that inherits from Nsvalue that is a collection of basic data types including char a signed or unsigned char, short int, int, long int, long long int, Floa T, or double or as a BOOL

The NSNumber type is a bit like the ID type, which can be declared for any type of numeric object, that is, it is used to declare a numeric object, it is very difficult to determine what type of number the declaring variable is, and to determine that the Number object type is determined at initialization time.

2.int:32 bit integral type

int is an integer type, signed
unsigned int is an unsigned integer type

When you use the int type to define a variable, you can use int or Nsinteger as a C program, and we recommend using Nsinteger because this does not have to consider whether the device is 32-bit or 64-bit (varies with compiler changes for different platform 32, The 64-bit has a different maximum value (int long).

3.

Nsuinteger are unsigned, that is, there are no negative numbers, and Nsinteger are signed.

Nsinteger is the underlying type, NSNumber is a class, if you need to store a numeric value, the direct use of nsinteger is not possible, such as in an array using the following statement will be error:*array = [Nsarray alloc ] init];  [Array AddObject: 3 ];  because the array should be a class, but '  3 ' No, so need to use NSNumber:*array = [Nsarray alloc] init]  ; [Array addobject:[nsnumber numberwithint:3]];  

IOS int Nsinteger NSNumber differentiate

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.