Reputation: 2098
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!
Upvotes: 21
Views: 4997
Reputation: 221
Don't forget to try a "Clean"! That fixed it for me even though I had deleted the app from my device.
Upvotes: 0
Reputation: 41
Alternatively, you can write your own setter/getter method that transforms the Int
into a NSNumber
instance and passes this on the the primitive value. E.g.:
private(set) var publicId: Int {
get {
self.willAccessValueForKey("publicId")
let value = self.primitivePublicId.longValue
self.didAccessValueForKey("publicId")
return value
}
set {
self.willChangeValueForKey("publicId")
self.primitivePublicId = NSNumber(long: newValue)
self.didChangeValueForKey("publicId")
}
}
@NSManaged private var primitivePublicId: NSNumber
Upvotes: 1
Reputation: 539775
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
.
Upvotes: 36