I converted code to Swift3 and got bug in decoding object.
Swift2 was :
required init(coder decoder: NSCoder) {
if let colorInt = decoder.decodeObjectForKey(colorKey) as? Int {
self.color = ColorTag(rawValue: colorInt) ?? .Black // NSColor
}
}
func encodeWithCoder(coder: NSCoder) {
coder.encodeObject(self.color.rawValue, forKey: colorKey)
}
}This is converted in Swift3 as :
required init(coder decoder: NSCoder) {
if let colorInt = decoder.decodeObject(forKey: colorKey) as? Int { // 25.12.2016
self.color = ColorTag(rawValue: colorInt) ?? .black // NSColor
}
}
func encode(with coder: NSCoder) {
coder.encode(self.color.rawValue, forKey: colorKey)
}
}Problem is that if let colorInt = decoder.decodeObject(forKey: colorKey) as? Int always returns nil
If I change decodeObject with decodeInteger, that works.
How is it that decoder.decodeObject cannot be cast as? Int
Are there many other traps like this in conversion ? Testing will be daunting.