Swift 3如何编码struct&枚举与NSCoding

时间:2017-03-05 05:43:56

标签: sprite-kit swift3 nscoding

我有一个动画类如下:

enum AnimationState: String {
    case idle = "idle"
    case walk = "walk"
}

struct Animation {
    let animationState: AnimationState
    //let facingDireaction: FacingDirection
    let speed: TimeInterval
    let textures: [SKTexture]
    let repeatForever: Bool
}

class AnimationComponent: GKComponent {
    var animations: [AnimationState: Animation]

   //Other codes.....
}

我尝试将动画编码如下:

override func encode(with aCoder: NSCoder) {
        aCoder.encode(self.animations, forKey: "AnimationComponent.animations") 
    }

我在尝试编码动画变量时遇到以下错误: _SwiftValue encodeWithCoder:]:无法识别的选择器发送到实例0x608000075540

我的理解是我必须做一些额外的工作来编码struct&枚举,但是如何?

提前感谢您的帮助。

0 个答案:

没有答案