問題はARCが原因ではなく、CベースのコアグラフィックスコードとObjective-CベースのNSCodingメカニズムの不一致が原因です。
NSCoding
エンコーダー/デコーダーを使用するには、Objective-Cプロトコルに準拠したオブジェクトを使用する必要があります。CGMutablePathRef
これはObjective-Cオブジェクトではなく、Core Graphicsオブジェクト参照であるため、準拠していません。
ただし、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
これは私のテストで機能します。