我的架构如下
RecordType:OwnedEvents包含一个名为" Owner"的元素。此Owner元素指向从类型" OwnedEvents"的RecordType创建的CKReference。
我有N OwnedEvents对象都指向一个所有者对象。
当我执行查询以检索指向给定所有者对象的所有记录时,我看到,在某些情况下,查询不会返回指向它的所有记录(在大多数情况下它会返回它)。它也不会在完成块中返回错误。当我转到CloudKit仪表板时,我发现所有OwnedEvents对象都指向了与预期相同且正确的Owner对象。我用来检索的代码如下。
我的问题是:
这种"沉默"失败预期?我需要识别并恢复吗?或者我在查询中做错了什么?
有没有办法说如果没有检索到符合条件的所有记录,查询必须返回错误? (即fetch的原子版本。我猜不是,因为很难提前知道匹配记录的预期数量是多少,但我想知道是否有我可以在fetch或schema中指定的内容提示获取结果中预期的最小记录数。)
使用与引用形成的谓词相比,使用形式的谓词获取提取效率更高效#34;使用列X获取所有OwnedEvents类型的记录> N1和X列
使用的代码
CKReference* recordToMatch = [[CKReference alloc] initWithRecordID:eventCollectionID
action:CKReferenceActionDeleteSelf]; //eventCollectionID is recordID of Record of type Owner
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"Owner == %@", recordToMatch];
// Create the query object.
CKQuery* query = [[CKQuery alloc] initWithRecordType:@"OwnedEvents" predicate:predicate];
CKQueryOperation *queryObject = [[CKQueryOperation alloc] initWithQuery:query] ;
queryObject.queryCompletionBlock = ^(CKQueryCursor * cursor, NSError * operationError) {
if(operationError)
{
DDLogError(@"Error %@ occured during query",operationError) ;
}
else if(cursor)
{
DDLogVerbose(@"Not all objects satisfying the query were returned. Need to get next batch") ;
//To do fetch remaining entries
CKQueryOperation *queryObject = [[CKQueryOperation alloc] initWithCursor:cursor] ;
//Execute another query with this object
}
else
{
DDLogVerbose(@"All objects satisfying the query were returned") ;
//Take appropriate action with rcvd data
}
} ;
queryObject.recordFetchedBlock = ^(CKRecord *record) {
DDLogVerbose(@"Received record with seq Num: %@, type",record[@"SequenceNumber"],record[@"EventType"]) ;
//Check if items are in sequence
} ;
[self.publicDatabase addOperation:queryObject] ;