问题
What I want to do:
Add a unique constraint on the attribute photoID
in the entity PhotoUpload
.
Problem:
I tap on constraints and add photoID
.
When I navigate to a different file and come back to the xcdatamodeld
file, the constraint is not present. It is automatically removed.
And so the unique constraint is not working.
What I have done so far:
- I have tried deleting the
xcdatamodeld
file and re-created it, but the same problem persists.
Screenshot:
Versions:
Xcode - 7.3.1
回答1:
I believe this to be a bug in Xcode. If you change the model to add (or amend or remove) a constraint, the underlying model file is not updated, even though the screen shows the changes correctly. To overcome it, change another element of the model at the same time as adding the uniqueness constraint. Save the model. Then change the other element back and save again.
来源:https://stackoverflow.com/questions/38496346/coredata-unique-constraints-disappears-in-xcode