I have a CoreData attribute on an entity on which I want to store integer values larger than Int32.max
and UInt32.max
. The value is used as an index, so lookup performance matters. So I've opted to use Integer 64
as datatype in CoreData.
Now I'm struggling on how to store an Int64 on my entity instance. See also the following different approaches I've tried.
Use NSNumber
:
import Foundation
import CoreData
class Node : NSManagedObject {
@NSManaged var id : NSNumber
}
node.id = Int64(1)
> 'Int64' is not convertible to 'NSNumber'
Use NSInteger
:
import Foundation
import CoreData
class Node : NSManagedObject {
@NSManaged var id : NSInteger
}
node.id = Int64(1)
> 'Int64' is not convertible to 'NSInteger'
Use Int64
:
import Foundation
import CoreData
class Node : NSManagedObject {
@NSManaged var id : Int64
}
node.id = Int64(1)
> EXC_BAD_ACCESS (code=1, address=...)
How should the attribute be defined / assigned in order to use 64 bit integers?