objc_boxable
OC可能你经常会看到@(100)等用法。不用奇怪,就是这个Function attributes
使用示例:
struct __attribute__((objc_boxable)) some_struct {
int i;
};
union __attribute__((objc_boxable)) some_union {
int i;
float f;
};
typedef struct __attribute__((objc_boxable)) _some_struct some_struct;
some_struct ss;
NSValue *boxed = @(ss);
NSValue转为自定义结构体:
struct __attribute__((objc_boxable)) MapPoint {
int x;
int y;
};
@interface NSValue(MapPoint)
- (struct MapPoint)mappointValue;
@end
@implementation NSValue(MapPoint)
- (struct MapPoint)mappointValue {
struct MapPoint point;
[self getValue:&point];
return point;
}
@end
网友评论