Is it safe, to modify the CoreData generated NSManagedObject properties from Int32 to Int?

When designing CoreData, we have to explicitly specific the bit of the used Integer

  • Integer 16
  • Integer 32
  • Integer 64

enter image description here

If we pick Integer 32, the Core Data generated NSManagedObject class would be

extension NSPlainNote {
    @NSManaged public var colorIndex: Int32
    ...
}

However, throughout rest of the application code, we are operating based on Int. Hence, it is pretty troublesome and error prone, of having to perform casting between Int32 and Int

I was wondering, is it a safe act, to modify the XCode generated class to

extension NSPlainNote {
    @NSManaged public var colorIndex: Int
    ...
}

Is there any potential pitfall we may fall into, if we choose to do so?


Solution 1:

As long as you're not concerned with exceeding Int32.max, there are no pitfalls to this. Integer sizes are not used in the SQLite data store, so Core Data doesn't actually care what size you use. The only potential issue would be if you really don't want values that are too large for Int32, because Int would allow larger values. I usually use "Integer 64" for everything unless I have some reason to limit the acceptable values in code.