您的问题不是由于ARC,而是由于基于C的Core Graphics代码与基于Objective-C的NSCoding机制之间的不匹配。
要使用编码器/解码器,您需要使用符合Objective-C NSCoding
协议的对象。 CGMutablePathRef
不符合,因为它不是一个Objective-C对象,而是一个核心图形对象引用。
但是,UIBezierPath
是一个CGPath的Objective-C包装,它符合。
你可以做到以下几点:
CGMutablePathRef mutablePath = CGPathCreateMutable();
// ... you own mutablePath. mutate it here...
CGPathRef persistentPath = CGPathCreateCopy(mutablePath);
UIBezierPath * bezierPath = [UIBezierPath bezierPathWithCGPath:persistentPath];
CGPathRelease(persistentPath);
[aCoder encodeObject:bezierPath];
,然后解码:
UIBezierPath * bezierPath = [aCoder decodeObject];
if (!bezierPath) {
// workaround an issue, where empty paths decode as nil
bezierPath = [UIBezierPath bezierPath];
}
CGPathRef path = [bezierPath CGPath];
CGMutablePathRef * mutablePath = CGPathCreateMutableCopy(path);
// ... you own mutablePath. mutate it here
这工作在我的测试。
[CGPathRef编码](http://stackoverflow.com/questions/1429426/cgpathref-encoding) – yuji 2012-03-30 08:08:21