Your problem is not due to ARC, but to the mismatch between Core Graphics code based in C and the NSCoding mechanism based in Objective-C.
To use encoders/decoders, you need to use objects that conform to the Objective-C NSCoding
protocol. CGMutablePathRef
does not conform since it is not an Objective-C object but a Core Graphics object reference.
However, UIBezierPath
is an Objective-C wrapper for a CGPath and it does conform.
You can do the following:
CGMutablePathRef mutablePath = CGPathCreateMutable();
// ... you own mutablePath. mutate it here...
CGPathRef persistentPath = CGPathCreateCopy(mutablePath);
UIBezierPath * bezierPath = [UIBezierPath bezierPathWithCGPath:persistentPath];
CGPathRelease(persistentPath);
[aCoder encodeObject:bezierPath];
and then to decode:
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
This works in my tests.