【发布时间】:2014-05-28 11:38:10
【问题描述】:
我正在尝试为 Cocoa 和 iOS 创建一个跨平台的 NSValue 类别,它将处理 CGPoint/NSPoint 和 CGSize/NSSize 等。
我有这个:
#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
// Mac OSX
+ (NSValue *) storePoint:(NSPoint)point {
return [NSValue valueWithPoint:point];
}
+ (NSPoint) getPoint {
return (NSPoint)[self pointValue];
}
#else
// iOS
+ (NSValue *) storePoint:(CGPoint)point {
return [NSValue valueWithCGPoint:point];
}
+ (CGPoint) getPoint {
return (CGPoint)[self CGPointValue];
}
#endif
Mac 部分运行良好,但 iOS 部分给我一个错误
return (CGPoint)[self CGPointValue];
有两条消息:1)没有已知的选择器 CGPointValue 的类方法和“使用类型 CGPoint(又名 struct CGPoint),其中需要算术或指针类型。
这是为什么呢?
【问题讨论】:
-
NSValue 类上没有 CGPointValue 方法。 developer.apple.com/library/mac/documentation/cocoa/reference/…
-
@HutinPuylo 里面有iOS rendition。
-
@HutinPuylo 在这里:developer.apple.com/library/ios/documentation/uikit/reference/…
标签: ios cocoa cgpoint cgsize nsvalue