UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Is it possible to use a predicate in SwiftUI FetchRequest to retrieve only the current users records from the public database?

Forums > SwiftUI

Hi

The SwiftUI app I am currently developing has private and public databases. When the public database is published to, I want to offer the user tha ability to edit their own records, however, I can't see how I can filter this as the created by field does not seem to be available as a predicate for FetchRequest.

My thinking was then to CKContainer and fetchUserRecordId and store the returned hash for recordName in the public record, and then use the predicate to compare to the value for the current user using a dynamic predicate. But that would make everyone's hash public, and I suspect that's a security hole, even if it is just my app and public data.

My other thinking is that I could keep track of a UUID assigned to the public record by recording it in a record in the private database and then use a dynamic predicate, but this seems clumsy and makes me think I must be doing something wrong. It would be simple enough to implement though, and in the absence of anything else, that's likely the way I will go.

I have looked also at canUpdateRecord etc - but these aren't filters from what I can see, they would return true after fetching and I don't want to fetch records that I don't need to. In fact when I tried them out to exclude in a list, they didn't work as I'd expected anyway.

So, does anyone know if there a simple way to only fetch records created by the current user from the public database in a SwiftUI app, or do I need to delve into CloudKit itself (or more likely, go with my private record of the UUIDs and dynamically create a predicate)?

Thanks,

Ian

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.