gpt4 book ai didi

ios - 跨平台 NSValue 类别

转载 作者:行者123 更新时间:2023-11-29 02:56:04 25 4
gpt4 key购买 nike

我正在尝试创建一个跨平台的 NSValue 类别,它将处理 Cocoa 和 iOS 的 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] 不存在你想要 -[NSValue CGPointValue]

#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
// Mac OSX

+ (NSValue *) storePoint:(NSPoint)point {
return [NSValue valueWithPoint:point];
}

- (NSPoint) getPoint { // this should be instance method
return (NSPoint)[self pointValue];
}


#else
// iOS

+ (NSValue *) storePoint:(CGPoint)point {
return [NSValue valueWithCGPoint:point];
}

- (CGPoint) getPoint { // this should be instance method
return (CGPoint)[self CGPointValue];
}


#endif

关于ios - 跨平台 NSValue 类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23910621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com