Closed foolbear closed 6 years ago
An OR predicate is not supported by CloudKit. See the documentation: https://developer.apple.com/documentation/cloudkit/ckquery
But... It should not crash.... Does it also crash when you just create the NSPredicate? Or does it crash in the .connect? At what line does it crash? What is the crash message?
So how to solved this solution? subscript each url?
crash at "let query: CKQuery = CKQuery(recordType: recordType, predicate: predicate)"
@discardableResult
open func query<T: CKDataObject>(_ type: T, predicate: NSPredicate, orderBy: OrderBy = Descending(field: "creationDate"), completionHandler: @escaping (_ results: [T], _ isFinished: Bool) -> Bool, errorHandler:((_ error: Error) -> Void)? = nil) -> CKQueryOperation {
let recordType = EVReflection.swiftStringFromClass(type)
**let query: CKQuery = CKQuery(recordType: recordType, predicate: predicate)**
query.sortDescriptors = orderBy.sortDescriptors()
return queryRecords(type, query:query, completionHandler: completionHandler, errorHandler: errorHandler)
}
Since its the same field you could create an ‘IN’ query.
You don't have to. You could use an 'in' query. There is a sample of that in the demo app. See the predicate:
NSPredicate(format: "From_ID in %@ AND To_ID in %@", [recordIdMeForConnection, recordIdOtherForConnection], [recordIdOtherForConnection, recordIdMeForConnection])
Here it even uses an 'in' for 2 fields. You can make the arrays as large as you like (with the url's)
let array = SHELFMANAGER().shelf.filter { $0 is Book }.flatMap { $0.bookFs.url }
let predicate = NSPredicate(format: "url in %@", array)
p.s. Above is untested. I hope I have the filter flatMap right... :-)
yeah, thanks!