Joshua
Joshua

Reputation: 1994

Changing a global identifier of a Core Data object with Ensembles

I am reading the Ensembles documentation where global identifiers should never change in an object life time. However, I have a Tag object which only consists with a name attribute (a string). According to the Ensembles documentation as well, the tag name can be returned as the global identifier, which is actually even better than returning a UUID for obvious reasons.

My question is, since the user is allowed to rename tags in my app, should I delete the tag object from the database and re-create it, or renaming the tag object is considered safe? (renaming the tag object will cause the app to return the new tag name as the global identifier, which seems to conflict with the warning of not changing global identifier in object's entire life cycle)

Thanks.

Upvotes: 1

Views: 79

Answers (1)

Drew McCormack
Drew McCormack

Reputation: 3592

You should not change the global id, so the tag objects should be considered immutable. You can delete them, or insert new ones, even ones also created on other devices. But don't ever change the global id.

My advice is to create a new tag object when the user renames. Depending on your model, that may mean changing relationships from one tag object to another, but that should work well.

The nice thing about global ids is that Ensembles can merge the relationship even if you create the same tag on two devices at once.

Upvotes: 3

Related Questions