ios - QueryOp with recordID -
i had recordid.recordname (singleid in example) , wanted query queryop; after searching , experimentation managed put code together... works, correct, there shorter path perhaps.
ckrecordid *wellknownidx = [[ckrecordid alloc] initwithrecordname:singleid]; ckreference *singlerex = [[ckreference alloc] initwithrecordid:wellknownidx action:ckreferenceactiondeleteself]; ckdatabase *publicdatabase = [[ckcontainer containerwithidentifier:@"icloud.blah"] publicclouddatabase]; nspredicate *predicatex = [nspredicate predicatewithformat:@"recordid == %@",singlerex]; ckquery *query = [[ckquery alloc] initwithrecordtype:@"courses" predicate:predicatex]; ckqueryoperation *queryop =[[ckqueryoperation alloc] initwithquery:query]; queryop.desiredkeys = @[@"record.recordid.recordname"]; queryop.resultslimit = 1; queryop.recordfetchedblock = ^(ckrecord *results) { nslog(@"student found %@",results.recordid.recordname); }; queryop.querycompletionblock = ^(ckquerycursor *cursor, nserror *error) { nslog(@"ckquerycursor error %@", error); }; [publicdatabase addoperation:queryop];
what have should work, looks want fetch record known recordid. there no need use query that. it's more code necessary , require query index on field.
instead, use fetchrecordwithid method on ckdatabase: https://developer.apple.com/library/ios/documentation/cloudkit/reference/ckdatabase_class/index.html#//apple_ref/occ/instm/ckdatabase/fetchrecordwithid:completionhandler:
Comments
Post a Comment