One definition in objective-c, we can use the numeric data types in C, int, float, long, and so on. They are all basic data types, not objects. That is, it is not possible to send messages to them. Then, there are times when you need to use these values as objects. Two key words 1 nsinteger int wrapper type A when you don't know which processor architecture The program is running, you'd better use Nsinteger, because it's possible for an int to be just int in a 32-bit system, whereas in a 64-bit system, an int can be a long type. Nsinteger is recommended unless you have to use the Int/long type. B from the definition above, it can be seen that Nsinteger/nsuinteger is a dynamically defined type, in different devices, different schemas, possibly an int type, possibly a long type. 2 Nsuinteger is unsigned, that is, there are no negative numbers, and the Nsinteger is signed. 3 NSNumber A is designed to hold an object of the underlying type, storing an integral type, single precision, double precision, character type, and other basic types as Object B nsnumber You can wrap the base data type to form an object so that you can send a message to it and load it into the Nsarray C Nsinteger and normal data types are not encapsulated in arrays.
////main.m//Oc-nsnumber////Created by Wangtouwang on 15/3/20.//Copyright (c) 2015 Wangtouwang. All rights reserved.//#import<Foundation/Foundation.h>intMainintargcConst Char*argv[]) {@autoreleasepool {//Insert code here ...//CreateNSNumber *_n1 = [[NSNumber alloc] Initwithint:9]; NSNumber*_N2 = [[NSNumber alloc] Initwithfloat:8.1f]; NSNumber*_N3 = [[NSNumber alloc] Initwithdouble:8.1]; NSNumber*_N4 = [[NSNumber alloc] Initwithchar:'A']; NSLog (@"n1=%@ n2=%@ n3=%@ n4=%@", _N1,_N2,_N3,_N4); //Restore//Convert to int intN1 =[_n1 Intvalue]; //Convert to Double DoubleN3 =[_n3 Doublevalue]; //Convert to float floatN2 =[_n2 Floatvalue]; //Convert to Char CharN4 =[_n4 Charvalue]; NSLog (@"n1=%i n2=%f n3=%f n4=%c", N1,N2,N3,N4); //comparison is equalNSLog (@"%@", [_n3 isequaltonumber:_n2]?@"==":@"!="); //Compare SizeNSLog (@"%ld", [_n1 compare:_n2]); //array can increase the NSNumber objectNsmutablearray *_array2 =[[Nsmutablearray alloc] initwithobjects:_n1,_n2,_n3,_n4, nil]; Nsinteger INDEX= A; //an attempt to add an array to an Nsinteger object results in an error stating that the syntax does not support//Nsmutablearray *_array1 = [[Nsmutablearray alloc] initwithobjects:_n1,_n2,_n3,_n4, Index,nil];//NSLog (@ "%lu", [_array1 Count]); } return 0;}
IOS Learning Note 2015-03-20 oc-numeric type