Hughesyy
Hughesyy

Reputation: 43

Swift: Save public CKRecord to private database

I'm new to CloudKit and Swift in general. I've set up an app that downloads records and puts them into a collection view. These records are movies. I'm looking for a way for a user to "like" a movie and then this movie gets moved to their "My Movies" view controller. The only way I can think to do this is by transferring the public data to the private database for that user. Then the "My Movies" gets populated with the movies they've "liked".

Any help is appreciated!

Upvotes: 2

Views: 702

Answers (1)

Edwin Vermeer
Edwin Vermeer

Reputation: 13127

You have to be aware that when you save data to the private database you can not query that data with an other account than the one that crated it. For your situation you could create a new recordType in the publicDatabase. That recordType would then have a field of type CKReference in which you save your user ID. Then you could add a 2nd field that contains an array of recordID's of the movies that are liked.

For creating the list of my movies, then first query that new recordType to find the record with the liked movies. Then after that query the movies where it's recordId is one of the liked recordId's

The benefit of this approach is that you could also query to see how often a certain movie is liked.

Upvotes: 1

Related Questions