Tim Tim - 2 months ago 43x
iOS Question

Core Data Scalar error only on some devices

I've been testing primarily using iPhone 6, 6 plus, and iPad. Just tried my app today on the iPhone 5 simulator, and got a Core Data error.

CoreData: error: Property 'setId:' is a scalar type on class 'AppName.EntityName' that does not match its Entity's property's scalar type. Dynamically generated accessors do not support implicit type coercion. Cannot generate a setter method for it

Now, there is no 'setId' object in my app, but of course the entity does have an 'ID' object, which is set as an int.

class Entity: NSManagedObject {
@NSManaged var id: Int

In the Core Data model, the attribute type is set to Integer64. That might be my problem, as I picked that without knowing what was best. I have other attributes in the model and class, but they are all strings.

Looking for both a fix and an explanation as to why this happens only on some devices, so I can learn!


If the Core Data type is Integer 64 then you should declare the property as Int64 (or let Xcode create the managed object subclass).

Int can be 32 bit or 64 bit, depending on the processor architecture.

Alternatively, define the property as NSNumber* instead of a scalar property. Of course you have to take care that on a 32-bit platform the values do not exceed the range of Int.