I'd like to be able to encode a class with an array of optional values. Xcode errors with "Cannot invoke 'encode object' with an argument list of type '([SKSpriteNode?], for key: String').
class MyCustomNode: SKNode {
var possibleSprites:[SKSpriteNode?] = [nil, nil, nil, nil, nil, nil, nil]
...
}
override func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(self.possibleSprites, forKey: "POSSIBLESPRITES")
super.encodeWithCoder(aCoder)
}
Is this possible to achieve? If not, what are other options?
Question on proper decoding...
With the following,
let x:[AnyObject!] = aDecoder.decodeObjectForKey("POSSIBLESPRITES") as! [AnyObject]
self.possibleSprites = x.map { $0 == NSNull() ? nil : $0 }
I get Xcode error: “Cannot invoke 'map' with an argument list of type '((_) -> _)'”
I believe it has to do with the return type, but not sure how to solve...