我想知道如何在 Cloud Kit 的私有数据库中获取一个包含所有记录类型名称的数组,以读取我的所有数据?
我保存我的数据:
CKRecord* fav1 = [[CKRecord alloc] initWithRecordType:@"Favoris1"];
[fav1 setObject:@"Favoris 1 name"forKey:@"name"];
[fav1 setObject:@"2003 year"forKey:@"year"];
[self.privateDatabase saveRecord:fav1
completionHandler:^(CKRecord *savedState, NSError *error) {
if (error) {
NSLog(@"ERROR SAVING: %@", error);
}
else{
NSLog(@"SAVE OK");
}
}];
我读了我的数据:
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Favoris1" predicate:[NSPredicate predicateWithFormat:@"TRUEPREDICATE"]];
[self.privateDatabase performQuery:query
inZoneWithID:nil
completionHandler:^(NSArray *results, NSError *error)
{
if (!error)
{
NSLog(@"results query %@", results);
NSLog(@"--> %@",[[results objectAtIndex:0] objectForKey:@"name"]);
NSLog(@"--> %@",[[results objectAtIndex:0] objectForKey:@"year"]);
}
else
{
NSLog(@"FETCH ERROR: %@", error);
}
}];
我想用其他属性保存另一条记录,例如:
CKRecord* fav2 = [[CKRecord alloc] initWithRecordType:@"Favoris2"];
[fav2 setObject:@"Favoris 2 name"forKey:@"name"];
[fav2 setObject:@"2005 year"forKey:@"year"];
保存后如何使用 Favoris1 和 Favoris2 读取我的所有记录?