For objective-c array Nsarray can only save objects, cannot access the base data type, such as Integer int, float float, double-precision floating-point double, char Char, but objective-c in order to be able to save the base data type to an array, There is a type called NSNumber, which is called a numeric object. (Some of the words are not very accurate, you will find the right word to be modified)
Use the following:
// convert integer int to nsnumber type
nsnumber * number_int = [[nsnumber alloc] initwithint:+];
// convert character char to nsnumber type
nsnumber * Number_char = [[nsnumber alloc] initwithchar:' A '];
// convert floating-point float to nsnumber type
nsnumber * number_float = [[nsnumber alloc] initwithfloat:2.0f];
// convert double-precision floating-point double to nsnumber type
nsnumber * number_double = [[nsnumber alloc] initwithdouble:5.6 ];
// beginners want to use keyboard input to assign values, in fact the principle is the same, for example: converting floating-point type C to nsnumber type
Char c ;
scanf ("%c", &c);
nsnumber * number_free = [[nsnumber alloc] Initwithchar: c];
// convert nsnumber type to integer int
int inumber = [Number_int intvalue];
// convert nsnumber type to character char
char cnumber = [Number_char charvalue];
// convert nsnumber type to float float
float fnumber = [number_float floatvalue];
// convert nsnumber type to Double-precision floating-point type
double dnumber = [number_double doublevalue];
/*
[number isequaltonumber: (NSNumber *)] A function is a method that compares two nsnumber types
The return value of the BOOL type is only two, Yes (that is, 1) and NO (that is, 0) .
the ascall code of ' a ' is
the value of the Number_int object is
The value of the Number_char object is ' a ', and the comparison is equal, because ' a ' is
*/
BOOL issame = [Number_int isequaltonumber: Number_char];
Objective-c Learning-Digital Object NSNumber