Background
I am trying to encode a String-style enum using the NSCoding protocol, but I am running into errors converting to and back from String.
I get the following errors while decoding and encoding:
String is not convertible to Stage
Extra argument ForKey: in call
Code
enum Stage : String
{
case DisplayAll = "Display All"
case HideQuarter = "Hide Quarter"
case HideHalf = "Hide Half"
case HideTwoThirds = "Hide Two Thirds"
case HideAll = "Hide All"
}
class AppState : NSCoding, NSObject
{
var idx = 0
var stage = Stage.DisplayAll
override init() {}
required init(coder aDecoder: NSCoder) {
self.idx = aDecoder.decodeIntegerForKey( "idx" )
self.stage = aDecoder.decodeObjectForKey( "stage" ) as String // ERROR
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeInteger( self.idx, forKey:"idx" )
aCoder.encodeObject( self.stage as String, forKey:"stage" ) // ERROR
}
// ...
}
?? .DisplayAll
is useless. Shouldn't it beas?
instead? – Penance