Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 在Cocoa和Cocoa Touch中存储NSArray中CGPoint的通用解决方案?_Cocoa Touch_Cocoa_Nsarray_Cgpoint - Fatal编程技术网

Cocoa touch 在Cocoa和Cocoa Touch中存储NSArray中CGPoint的通用解决方案?

Cocoa touch 在Cocoa和Cocoa Touch中存储NSArray中CGPoint的通用解决方案?,cocoa-touch,cocoa,nsarray,cgpoint,Cocoa Touch,Cocoa,Nsarray,Cgpoint,我想在Cocoa和Cocoa Touch应用程序之间共享一个类。此类计算各种CGPoints并将其存储在数组中。在Cocoa中有[NSValue valueWithPoint]。在Cocoa Touch中有[NSValue valueWithCGPoint] 是否有任何解决方案允许我绕过使用这些特定于框架的方法?您可以在NSValue上创建一个类别,以便将valueWithCGPoint:和CGPointValue方法添加到Cocoa中 #if ! TARGET_OS_IPHONE @inter

我想在Cocoa和Cocoa Touch应用程序之间共享一个类。此类计算各种
CGPoint
s并将其存储在数组中。在Cocoa中有
[NSValue valueWithPoint]
。在Cocoa Touch中有
[NSValue valueWithCGPoint]


是否有任何解决方案允许我绕过使用这些特定于框架的方法?

您可以在
NSValue
上创建一个类别,以便将
valueWithCGPoint:
CGPointValue
方法添加到Cocoa中

#if ! TARGET_OS_IPHONE @interface NSValue (MyCGPointAddition) + (NSValue *)valueWithCGPoint:(CGPoint)point; - (CGPoint)CGPointValue; @end #endif
令人惊叹的!我使用了最后一个建议。对于一个类别,我仍然需要显式地导入一个框架,这是我想要避免的。谢谢 #if ! TARGET_OS_IPHONE @implementation NSValue (MyCGPointAddition) + (NSValue *)valueWithCGPoint:(CGPoint)point { return [self valueWithPoint:NSPointFromCGPoint(point)]; } - (CGPoint)CGPointValue { return NSPointToCGPoint([self pointValue]); } @end #endif CGPoint point = {10, 10}; NSValue *value = [NSValue valueWithBytes:&point objCType:@encode(CGPoint)]; // ... [value getValue:&point];