문제

I have a subclass of SKShapenode with 2 extra attributes

@property(assign)float size;
@property(assign)float weight;

But when I save a NSMutableArray, with core data, containing some subclasses of my node, the information about size + weight is lost.

newLevel.tractorObjects = [NSKeyedArchiver archivedDataWithRootObject:arrayTractorObjects];

How can I solve this problem?

도움이 되었습니까?

해결책

Since you appear to be using NSCoding to encode the nodes, you need to implement NSCoding in your subclass. Right now SKShapeNode is doing all of the encoding, but it doesn't know about your subclass attributes. To get your attributes encoded, you need to implement encodeWithCoder and initWithCoder. Both of these should call super's implementation so that SKShapeNode can encode itself, and then add/extract your own attributes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top