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 help me?
In that case, how can I "validate" a ID to be unique? Should I write a validation method or something?
Your options are:
-[NSManagedObject objectID]
. Note that this ID is temporary until either the object is saved for the first time or you call -[NSManagedObjectContext obtainPermanentIDsForObjects:error:]
CFUUID
family of functions to generate a UUID for each object in your -awakeFromInsert
methodThere is no good way to validate that a property is unique. The closest you'll get is to ensure it is unique at creation time, and then implement a custom setter method that stops anyone ever changing the ID.