Need help with this!
Welcome to the community!
Does it have to be an integer? Inherently you can’t auto increment an int (from my research)
But you could make an id field that is type UUID.
Otherwise another solution would be to save a user default value and use that to save/increment from
From my research, I have been told that xcode has added a new feature for auto incrementing an Int i’d in core data. But i couldnt find it anywhere. Anyways thanks for the suggestion.
Core Data does not have a way to autoincrement a field. The correct thing to do is to ask yourself why you think you need such a thing. In databases, autoincremented
ids are used to guarantee uniqueness of rows. But, when using Core Data, the most important thing to remember is this: Core Data is not a database.
If you are looking for a way to get a unique id for your Core Data entities, you can always use the
objectID property., which returns an
NSManagedObjectID. You can convert that to a string through its
uriRepresentation property if you need to display it or save it for some reason. Just remember that your objects will have a temporaray
objectID assigned when they are created and a permanent one assigned when they get saved into your managed object context.