Objective-Cプログラミング:NSValue
1509 ワード
NSValueメソッド
+ (NSValue *)valueWithPoint:(NSPoint)point;
+ (NSValue *)valueWithSize:(NSSize)size;
+ (NSValue *)valueWithRect:(NSRect)rect;
+ (NSValue *)valueWithEdgeInsets:(NSEdgeInsets)insets NS_AVAILABLE(10_10, 8_0);
CGPoint
// NSPoint
NSPoint somePoint = NSMakePoint(100, 100);
NSValue *point = [NSValue valueWithPoint:somePoint];
// CGPoint
NSValue *myPointValue = [NSValue valueWithPoint:CGPointMake(10, 10)];
CGPoint point = [myPointValue pointValue];
CGSize
//
NSValue *mySizeValue = [NSValue valueWithSize:CGSizeMake(375, 664)];
CGSize size = [mySizeValue sizeValue];
CGRect
//
NSValue *myRectValue = [NSValue valueWithRect:CGRectMake(0, 0, 375, 664)];
CGRect rect = [myRectValue rectValue];
NSRange
//
NSValue *myRangeValue = [NSValue valueWithRange:NSMakeRange(0, 10)];
NSRange range = [myRangeValue rangeValue];
こうぞうたい
// 、
struct WXpoint {
float a;
float b;
};
struct WXpoint p = {10,50};
//
NSValue *pointvalue1 = [NSValue value:&p
withObjCType:@encode(struct WXpoint)];
//
struct WXpoint p2;
[pointvalue1 getValue:&p2];