I'm unarchiving a Swift class with the following Swift code:
required convenience init(coder decoder: NSCoder) {
self.init()
horseID = decoder.decodeIntegerForKey("horseID")
name = decoder.decodeObjectForKey("name") as String!
// if the thumb key does not exist, the following line crashes
thumb = decoder.decodeObjectForKey("thumb") as UIImage!
}
The "thumb" class member was added later. I have an older archive file without the thumb data in it. Apple's documentation says that unarchiving a non-existing key returns a nil. This is the familiar Objective-C behavior. My Swift code crashes with error code: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
Changing from as
to as?
doesn't remove the problem.
This makes it difficult to extend a data model in a new version. Am I doing something wrong? I'm new to Swift.