如何在CloudKit Dashboard中使用“fetchWithRecordID”自动生成ID?

我是CloudKit和iOS开发的新手。 我已经手动添加了一些logging到CloudKit Dashboard,现在我想通过自动创build的ID检索它们。 然后我想显示一个logging的值在一个静态tableview单元格的UILabel。 有两个问题:1)。 从控制面板使用ID时,出现xCode错误(错误显示为“expected”,“separator”); 和2)。 我找不到在静态tableview单元格中的UILabellogging值的任何示例。 (特别是快速)。 任何帮助是极大的赞赏!

这是我的代码:

override func viewDidLoad() { super.viewDidLoad() publicDB.fetchRecordWithID (f7080e7a-f8c3-4db6-b8ee-642a011a6762) { record, error in if error != nil { println("there was an error \(error)") } else { // this is my UILabel in a static tableview. The record's only attribute is //called "subCategory" plasticOneValue.text = record["subCategory"] } } } 

更新:另外 – 我试过这个代码,并build设成功,但控制台说,它有一个内部错误,UILabel仍然是空白……任何build议我做错了上面的代码或此代码?

 override func viewDidLoad() { super.viewDidLoad() // I created a new CKRecord ID Object and provided the existing ID in dashboard and //it fixed the error about requiring a "," separator var plasticOneID = CKRecordID(recordName: "f7080e7a-f8c3-4db6-b8ee-642a011a6762") publicDB.fetchRecordWithID (plasticOneID) { record, error in if error != nil { println("there was an error \(error)") } else { self.plasticOne.text = (record.objectForKey("subCategory") as String) } } } 

这是两个不同的问题

  1. 当查询一个ID时,你必须像在第二个样本中一样查询CKRecordID
  2. 访问用户界面时,必须在主队列上执行此操作。

那么代码会是这样的:

 publicDB.fetchRecordWithID(CKRecordID(recordName: "f7080e7a-f8c3-4db6-b8ee-642a011a6762"), completionHandler: {record, error in if error != nil { println("there was an error \(error)") } else { NSOperationQueue.mainQueue().addOperationWithBlock { self.plasticOne.text = (record.objectForKey("subCategory") as String) } } })