Post

Replies

Boosts

Views

Activity

Reply to Anyway to specify a unique constraint in Cloudkit record?
Hi everyone! Is this a feature yet? Here is my use case... I have an iOS app using CloudKit for the backend. I have a record for custom user called MyUser. Each MyUser record has a field called username. I want to let the users edit their usernames on the app but I also want to make sure there are no duplicate usernames. If a user tries to change their username to a username that is already taken I want them to see an error. If I could mark the username field as must be unique on CloudKit, then when I send the network request to change the username CloudKit will send an error back if it is taken. Without this, I can implement my own check to see if a username is taken by querying the MyUser records by username. But what if two different apps query for the same username at the same time... yes there is only a very small chance of this happening but it is NOT impossible. The queries would return with no users ( aka username is available ) and then both users would send the next network request to change their usernames to the same username. Is there a better way to achieve this? I think marking the username field on the MyUser record as "isUnique" would be very handy.
Apr ’24