iOS中的NSNumber与NSValue

2018-09-13  本文已影响0人  皆为序幕_

NSNumber(只能包装数字类型)

    NSNumber *num1 = [NSNumber numberWithInt:10];
    NSNumber *num2 = [NSNumber numberWithFloat:10.1];
    NSNumber *num3 = [NSNumber numberWithBool:YES];
    NSNumber *num4 = @10;

NSValue(可以包装结构体)

+ (NSValue *)valueWithCGPoint:(CGPoint)point;
+ (NSValue *)valueWithCGVector:(CGVector)vector;
+ (NSValue *)valueWithCGSize:(CGSize)size;
+ (NSValue *)valueWithCGRect:(CGRect)rect;
    CGPoint point =  CGPointMake(10,20);
    NSValue *value = [NSValue valueWithCGPoint:point];
    NSLog(@"%@",value);//NSPoint: {10, 20}
上一篇下一篇

猜你喜欢

热点阅读