我对CKQuery的工作原理有一个基本的误解。
我有2种记录类型:
我只是在徘徊如何查询投票表
上的 url_of_profil_pic基本上,想要这样的东西:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"the_one_who_vote = %@", recordReference.recordID];
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Votes" predicate:predicate];
query.sortDescriptors = [NSArray arrayWithObject:[[NSSortDescriptor alloc]initWithKey:@"createdAt" ascending:false]];
CKQueryOperation *operation = [[[CKQueryOperation alloc] initWithQuery:query] autorelease];
operation.desiredKeys = @[@"target_of_the_vote . url_of_profil_pic"];
operation.resultsLimit = 10;
operation.recordFetchedBlock = ^(CKRecord * _Nonnull record)
此行将是给我URL的谓词。
operation.desiredKeys = @[@"target_of_the_vote . url_of_profil_pic"];
答案 0 :(得分:0)
假设您已获取记录,并且url_of_profil_pic
是CKAsset
,则必须将资产URL转换为Data
对象,然后才能将其保存到这样的文件中:
//record is the CKRecord you fetched
if let asset = record["url_of_profil_pic"] as? CKAsset{
do{
try yourData = Data(contentsOf: asset.fileURL)
//Save yourData to disk...
}catch{
print("Error saving profile pic from CKAsset")
}
}
Apple建议将超过 1MB 的内容保存为CKAsset
在CloudKit(docs)上。