I'm not sure why exactly you want to do this, and if you really need to use key encoding, is it for obj-c compatibility?
It could be something that will be fixed later when Swift is updated. But now a (temporary) workaround might be to override the valueForKey function and take special care of your options. Something like that:
override func valueForKey(key: String!) -> AnyObject! { if key == "isActive" { if self.isActive == nil { return NSNumber(bool: false) } else { return NSNumber(bool: self.isActive!) } } return super.valueForKey(key) }
Keep in mind that I never ever use key value encoding, so I donโt know if it is a bad idea to override this function ... Also in obj-c BOOL is not nillable, so I assume you want false in this case ? (For Bool types, I would probably rather skip the optional option)
source share