NSNumber生成: NSNumber *number1 = [[NSNumber alloc] initWithInt:1000]; 转成NSNumber型: // short型→NSNumber型 NSNumber *num = [NSNumber numberWithShort:32767]; // int型→NSNumber型 NSNumber *num = [NSNumber numberWithInt:2147483647]; // long型→NSNumber型 NSNumber *num = [NSNumber numberWithLong:2147483647]; // float型→NSNumber型 NSNumber *num = [NSNumber numberWithFloat:42.195f]; // double型→NSNumber型 NSNumber *num = [NSNumber numberWithDouble:3.1415f]; // BOOL型→NSNumber型 NSNumber *num = [NSNumber numberWithBool:YES]; // char型→NSNumber型 NSNumber *num = [NSNumber numberWithChar:a]; NSNumber型转为NSString型:(同理,short/int/long/float/bool/char Value) NSString *str = [num stringValue]; NSNumber型是否相同的比较: BOOL b = [num1 isEqualToNumber:num2];
NSNumber NScopy,布布扣,bubuko.com
时间: 2024-10-12 01:28:22