【发布时间】:2013-02-16 18:39:59
【问题描述】:
我想将 NSCoding 支持添加到 c 结构数组。具体来说,这是MKPolyline 的子类,即这是我必须使用的:
@property (nonatomic, readonly) MKMapPoint *points;
@property (nonatomic, readonly) NSUInteger pointCount;
+ (MKPolyline *)polylineWithPoints:(MKMapPoint *)points count:(NSUInteger)count;
I found a good answer on how to encode a individual struct。例如
NSValue* point = [NSValue value:&aPoint withObjCType:@encode(MKMapPoint)];
[aCoder encodeObject:point forKey:@"point"];
....
NSValue* point = [aDecoder decodeObjectForKey:@"point"];
[endCoordinateValue getValue:&aPoint];
有没有一种很好的方法可以将它应用到 c 数组 - 还是我只需要遍历 c 数组?
【问题讨论】:
-
[NSValue value:aPointArray withObjCType:@encode(MKMapPoint[12])]或类似的怎么样? -
@H2CO3 在未来的版本中可能会弃用此方法。你应该改用
valueWithBytes:objCType:。 -
@voromax 没有检查文档,只是重复了 OP 的内容,但确实如此。
标签: ios objective-c cocoa-touch nscoding