I have a "table" that can potentially have many records, when adding a new record I need to know how many records there already are in current table as I use it in calculation of some values. The closest thing I could find is requesting all entries like this:
var query : CKQuery = CKQuery(recordType: "Stars", predicate: NSPredicate(format: "mass > 0"))
var request : CKQueryOperation = CKQueryOperation(query: query)
var starCount = 0
request.queryCompletionBlock = {
(cursor:CKQueryCursor!, error:NSError!) in
if error {
completionHandler(ECOResponse.error(error.description), starCount)
} else {
completionHandler(ECOResponse.ok(), starCount)
}
}
request.recordFetchedBlock = {
(record:CKRecord!) in
starCount += 1
}
I wish queryCompletionBlock gave a count or results array along with CKQueryCursor, but unfortunately it does not.
Is there any other way to calculate number of rows in the table?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…