I have
var priority : Priority! = Priority.defaultPriority
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeInteger(priority.toRaw(), forKey: "priority") //toRaw may not yield the result I am expecting
}
required init(coder aDecoder: NSCoder) {
priority = aDecoder.decodeIntegerForKey("priority") //complaining about conflicting types
}
枚举值如下:
enum Priority : Int {
case defaultPriority = 0
case lowPriority = 1
case mediumPriority = 2
case highPriority = 3
}
什么是最佳的编码/解码方式?