Unique record ID’s

I'm trying to create a column that represents a unique record ID, and can't seem to figure out how to create it. I'm using CoreData on iOS 9.x with a SQLite backing store.


The simple scenario is a table which should only have a single record which represents the last stored game number for each of several different game levels. I want to ensure that there is only one record in this table so that I can query the proper column for the last game number of that game type or level.

The idea being a single record that would have columns such as:

  • Last Easy Game Number Played
  • Last Hard Game Number Played, etc.

The game type/level, game number is then an indexed value in the game level preset values table. In this way I can query the last game number, search for a value greater than that, or else wrap around to game number 1 of that level to start the game.


The ability to create a unique index or primary key is beyond my mental grasp, (or use the record UUID saved by SQLite) but I know it is in either the index creation or the constraint creation. Yet I've queried the forum and the documentation for anything on creating either of these and don't see it. This surprises me - that it's not in the documentation - but the fact that it's not in the forum tells me it's something obvious that I'm not seeing.


Can anyone give me a clue on this, please?


Thanks very much in advance!

Accepted Answer

If you want to specify that a particular attribute should have unique values in iOS 9, that's done in the data model editor. In Xcode 7, the Data Model Inspector tab for the entities has a box for "Indexes" and a box for "Contraints".


Those boxes are where you need to specify the attribute that you're trying to create as a unique index for the object.


Edit: If you have any questions, watch the WWDC 2015 Core Data video.

Hi NotMyName,


Thanks VERY much for this answer - it solved my problem and your explanation and the video made it all clear. I got lost in my project and forgot to respond (kinda like the video for Aha's 'Take On Me' back in the 90's.... just to date myself....)


Thanks again - I really appreciate and very sorry for not responding sooner!

Unique record ID’s
 
 
Q