This may seem stupid, but I still couldn\'t figure out how to mark a attribute as a primary key in the xcdatamodel file. My persistent storage is sqlite file. Can anyone hel
A Swift Extension to retrieve the primary key
extension NSManagedObject {
var primaryKey : String {
guard objectID.uriRepresentation().lastPathComponent.count > 1 else { return "" }
return objectID.uriRepresentation().lastPathComponent.substring(from: 1)
}
}
And for String
extension String
{
func substring(from : Int) -> String {
guard self.count > from else { return "" }
return String(self[self.index(self.startIndex, offsetBy: from)...])
}
}