本文介绍了使用ARC编码和解码CGMutablePathRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ARC下,是否可以使用NSCodingCGMutablePathRef(或其非可变形式)进行编码/解码?我天真地尝试:

Under ARC, is it possible to encode/decode a CGMutablePathRef (or its non-mutable form) using NSCoding? Naively I try:

path = CGPathCreateMutable();
...
[aCoder encodeObject:path]

但是我从编译器中得到一个友好的错误:

but I get a friendly error from the compiler:

Automatic Reference Counting Issue: Implicit conversion of an Objective-C pointer to 'CGMutablePathRef' (aka 'struct CGPath *') is disallowed with ARC

该怎么编码?

推荐答案

NSCoding是协议.它的方法只能用于符合NSCoding协议的对象. CGPathRef甚至不是对象,因此NSCoding方法将无法直接工作.这就是为什么您会收到该错误.

NSCoding is a protocol. Its methods can only be used with objects that conform to the NSCoding protocol. a CGPathRef isn't even an object, so NSCoding methods won't work directly. That's why you're getting that error.

这是一个人,他提出了一种序列化CGPath的方法.

Here's a guy who has come up with a way to serialize CGPaths.

这篇关于使用ARC编码和解码CGMutablePathRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 05:11