3
問題是在獲取UserRecordID時從用戶記錄中獲取數據。使用UserRecordID獲取CloudKit用戶記錄
方法來獲得用戶ID: post.creatorUserRecordID .recordName
我的用戶記錄類型包含了諸如用戶名列,所以,我需要分析他們的具體用戶?以某種方式可能嗎?
問題是在獲取UserRecordID時從用戶記錄中獲取數據。使用UserRecordID獲取CloudKit用戶記錄
方法來獲得用戶ID: post.creatorUserRecordID .recordName
我的用戶記錄類型包含了諸如用戶名列,所以,我需要分析他們的具體用戶?以某種方式可能嗎?
如果我理解你的問題,並且你已經有一個CKRecordID。你所要做的就是使用你得到的這個CKRecordID來獲取RecordRecordWithID。
let publicDatabase = CKContainer.defaultContainer().publicCloudDatabase
publicDatabase.fetchRecordWithID(recordId, completionHandler: { (fetchRecord: CKRecord?, fetchError: NSError?) in
if let error = fetchError
{
// error getting user record, try again
print("-> cloudKitFetchUserRecord - error fetching user record - Error \(error)")
}
else
{
if let record = fetchRecord
{
if record.recordType == CKRecordTypeUserRecord
{
// valid record
print("-> cloudKitFetchUserRecord - fetching user record - valid record found - \(record.recordID.recordName))")
// unwrap your values - on your case username
if let object = record.objectForKey("username") as? Bool
{
// do something with object
}
}
else
{
// not valid record
print("-> cloudKitFetchUserRecord - fetching user record - The record that came back is not a CKRecordTypeUserRecord")
}
}
else
{
// record nil
print("-> cloudKitFetchUserRecord - fetching user record - fetch record returned nil")
}
}
})