IOS Study Notes 2015-03-20 OC-value type, 2015-03-20oc-
1. defined in Objective-C, we can use the numeric data types in c, such as int, float, and long. They are all basic data types, not objects. That is to say, messages cannot be sent to them. Then, you may need to use these values as objects. 2 keyword 1 NSInteger int packaging type A when you don't know which processor architecture the program runs, you 'd better use NSInteger, because it is possible that int Is only int type in 32-bit systems, in 64-bit systems, int type may change to long type. NSInteger is recommended unless you have to use the int/long type. B. From the above definition, we can see that NSInteger/NSUInteger is a dynamically defined type. different devices and architectures may be of the int type or long type. 2 NSUInteger is unsigned, that is, there is no negative number, and NSInteger is signed. 3 NSNumber A is specially used to store basic types of objects, such as integer, single precision, double precision, and character type as object B NSNumber. It can encapsulate basic data types to form an object, in this way, you can send messages to NSArray. The C NSInteger and common data types in NSArray cannot be encapsulated in the array.
//// Main. m // OC-NSNumber /// Created by wangtouwang on 15/3/20. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import <Foundation/Foundation. h> int main (int argc, const char * argv []) {@ autoreleasepool {// insert code here... // create NSNumber * _ 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 n1 = [_ n1 intValue]; // convert to double n3 = [_ n3 doubleValue]; // convert to float n2 = [_ n2 floatValue]; // convert to char n4 = [_ n4 charValue]; NSLog (@ "N1 = % I N2 = % f N3 = % f n4 = % c", n1, n2, n3, n4 ); // is the comparison equal to NSLog (@ "% @", [_ n3 is1_tonumber: _ n2]? @ "= ":@"! = "); // Compare the NSLog size (@" % ld ", [_ n1 compare: _ n2]); // The NSNumber object NSMutableArray * _ array2 = [[NSMutableArray alloc] initWithObjects: _ n1, _ n2, _ n3, _ n4, nil]; NSInteger INDEX = 12; // an error is returned when an NSInteger object is added to an array, indicating that the syntax does not support // NSMutableArray * _ array1 = [[NSMutableArray alloc] initWithObjects: _ n1, _ n2, _ n3, _ n4, INDEX, nil]; // NSLog (@ "% lu", [_ array1 count]);} return 0 ;}