Auto Generated Values Attributes

Hi


suppose I want an attribute to hold a unique number auto generated for each record in an entity in core Data, is there something out of the box in core Data to use ?

--

Kindest Regards

Answered by Claude31 in 416443022

A simple way would be to store in the record the duration converted in milliseconds from a start date.

That would surely be unique. And directly in sequential order if you need.

But if you fear simultaneous update at the same millisecond (highly improbable), add 3 digits number built from a unique record. Then risk is virtually zero.

Accepted Answer

A simple way would be to store in the record the duration converted in milliseconds from a start date.

That would surely be unique. And directly in sequential order if you need.

But if you fear simultaneous update at the same millisecond (highly improbable), add 3 digits number built from a unique record. Then risk is virtually zero.

In the world of 'unique' there is NSUUID. The problem of uniqueness is that if you have N selections, in order to assure uniqueness you need a number of order N*N.


https://developer.apple.com/documentation/foundation/nsuuid?language=objc

Auto Generated Values Attributes
 
 
Q