Share some of the things you don't pay attention to in your work project:
1. When you need to use a variable of type int, you can use int or Nsinteger as a program written C, but it is more recommended that Nsinteger be used, as this will not be considered 32-bit or 64-bit for the device.
2.NSUInteger is unsigned, that is, there are no negative numbers, and the Nsinteger is signed.
3. It is said that since all of these basic types are nsinteger, why should there be nsnumber? Their functions are, of course, different.
Nsinteger is the underlying type, but NSNumber is a class. If you want to store a value in Nsmutablearray, it is not possible to use Nsinteger directly, such as in a nsmutablearray:
Nsmutablearray *array = [[Nsmutablearray alloc]init];
[Array Addobject:[nsnumber numberwithint:88];
This will cause a compilation error, because the Nsmutablearray needs to be a class, but ' 88 ' is not a class.
Cocoa provides a basic data type that is packaged (that is, implemented as an object) by the NSNumber class.
For example, the following creation method:
+ (NSNumber *) Numberwithchar: (char) value;
+ (NSNumber *) Numberwithint: (int) value;
+ (NSNumber *) Numberwithfloat: (float) value;
+ (NSNumber *) Numberwithbool: (BOOL) value;
Once the base type data is encapsulated in NSNumber, it can be retrieved by using the following instance method:
-(char) charvalue;
-(int) intvalue;
-(float) floatvalue;
-(BOOL) boolvalue;
-(NSString *) stringvalue;
Example:
NSNumber *num = [nsnumber numberwithint:]; Nsinteger integer = [num intvalue];
5. Conversion between NSString and Nsinteger
888; string = [NSString stringWithFormat:@ "%d", Integernumber]; NSLog (@ "string is%@string);
Integer = [string intvalue]; NSLog (@ "integer is%d", integernumber);
Such conversions can be done in the same way as Char float.
iOS Development Int,nsinteger,nsuinteger,nsnumber