I'm building an app which allows users to upload / download info from a common store. I thought cloudKit storage would be ideal for this.
I'd like for users to be able to search records in the store by a KeyWord field, then download the entire record when they select one.
In SQL terms this would be like:
SELECT id,KeyWords from myDB WHERE KeyWords LIKE %searchstring%
Followed by:
SELECT * FROM myDB WHERE id = selectedID
I have been using this code pattern to retrieve records from cloudKit storage:
var publicDatabase: CKDatabase?
let container = CKContainer.defaultContainer()
override func viewDidLoad() {
super.viewDidLoad()
publicDatabase = container.publicCloudDatabase
}
func performQuery(){
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Library", predicate: predicate)
publicDatabase?.performQuery(query, inZoneWithID: nil,
completionHandler: ({results, error in
...
[code to handle results / error here]
...
})
}
but this returns all the content of each record which is a lot of unnecessary info.
I'd like to only fetch a single field from the cloudkit records.
Is there an easy way to do this and does anyone have a code snippet?
CKFetchRecordsOperation allows downloading of restricted columns but requires that you know the ids of the records to download.