I still muck up with bool’s in my core data config data. The NSManagedObject for say a core data “config” class one can quickly type in the following and you don’t get an error:
if (self.myCoreDataConfigObject.isOn) { ...
but it doesn’t give the correct result as what is required is the conversion from NSNumber to a bool:
if ([self.myCoreDataConfigObject.isOn boolValue]) { ...
Question – Any tips/tricks on how to avoid this? It would be great if XCode would show a warning in this case…
You could rename the field to something like
isOnValueand then provide an accessor on yourNSManagedObjectsubclass calledisOnthat runs the-boolValueconversion for you.Don’t forget, however, that “optional” values may be
niland you may care about this as something distinct thanNO.