NSNumber*intNum = [[NSNumberalloc]initWithInt:5];
NSNumber*floatNum = [[NSNumberalloc]initWithFloat:5.0f];
NSNumber*doubleNum = [[NSNumberalloc]initWithDouble:5.0f];
NSNumber*charNum = [[NSNumberalloc]initWithChar:'A'];
//或者...
// NSNumber *intNum1 = [NSNumber numberWithInt:6];
// NSNumber *floatNum1 = [NSNumber numberWithFloat:6.0];
// NSNumber *doubleNum1 = [NSNumber numberWithDouble:6.0];
// NSNumber *charNum1 = [NSNumber numberWithChar:'A'];
if([intNumcompare:floatNum] ==NSOrderedAscending) {
NSLog(@" < ");
}elseif([intNumcompare:floatNum] ==NSOrderedDescending){
NSLog(@" > ");
}elseif([intNumcompare:floatNum] ==NSOrderedSame){
NSLog(@" == ");
}
BOOLb = [intNumisEqualToNumber:floatNum];
NSLog(@"======%d",b);
NSLog(@"---- %d -----",[intNumintValue]);
NSLog(@"---- %f -----",[floatNumfloatValue]);
NSLog(@"---- %f -----",[doubleNumdoubleValue]);
NSLog(@"---- %c -----",[charNumcharValue]);
输出:
2015-09-24 10:06:04.394 test[1475:395290] <
2015-09-24 10:06:04.396 test[1475:395290] ======1
2015-09-24 10:06:04.396 test[1475:395290] ---- 5 -----
2015-09-24 10:06:04.396 test[1475:395290] ---- 5.000000 -----
2015-09-24 10:06:04.396 test[1475:395290] ---- 5.000000 -----
2015-09-24 10:06:04.396 test[1475:395290] ---- A——
1.strong :除NSString\block以外的OC对象
@property(nonatomic,strong) NSArray *<#model#>;
2.weak:各种UI控件(但不是绝对,也有控件要使用strong属性的)
@property (nonatomic,weak) UIButton *button;
3.assign:CGFloat,NSInteger等基本数据类型、枚举、结构体(非OC对象)
@property(nonatomic,assign) CGFloat <#model#>;
4.copy:
copy : 创建的是不可变副本(如NSString、NSArray、NSDictionary)
mutableCopy :创建的是可变副本(如NSMutableString、NSMutableArray、NSMutableDictionary)
@property(nonatomic,copy)NSString *<#model#>;
•@property内存管理策略的选择
•1.非ARC
• 1> copy : 只用于NSString\block
• 2> retain : 除NSString\block以外的OC对象
• 3> assign : 基本数据类型、枚举、结构体(非OC对象),当2个对象相互引用,一端用retain,一端用assign
•2.ARC
• 1> copy : 只用于NSString\block
• 2> strong : 除NSString\block以外的OC对象
• 3> weak : 当2个对象相互引用,一端用strong,一端用weak
• 4> assgin : 基本数据类型、枚举、结构体(非OC对象)