CloudKit ___recordID未标记为可查询

时间:2015-05-20 06:43:40

标签: objective-c xcode swift cloudkit

我尝试以编程方式将数据保存到CloudKit,但是当我从CloudKit获取数据时出现错误

我收到了错误

> <CKError 0x608000052060: "Invalid Arguments" (12/2015); server message
> = "Field '___recordID' is not marked queryable"; uuid = 19F1E556-5384-42FD-8F65-9FD8A9C9523D; container ID =
> "iCloud.com.mywebsite.CloudDemo">

这是我的代码。

func saveNewRecordTypeToCloud()  {
        // Prepare the record to save
        var record = CKRecord(recordType: "Members")
        record.setValue("test", forKey: "name")
        record.setValue("test", forKey: "surname")

        // Get iCloud Database
        let cloudContainer = CKContainer.defaultContainer()
        let database = CKContainer.defaultContainer().privateCloudDatabase

        // Save the record to iCloud
        database.saveRecord(record, completionHandler: { (record:CKRecord!, error:NSError! ) in
            if error != nil {
                NSLog(error.localizedDescription)
            } else {
                dispatch_async(dispatch_get_main_queue()) {
                    println("finished")
                }
            }
        })



    }



 func getRecordsFromCloud() {
        // Fetch data using Convenience API
        let cloudContainer = CKContainer.defaultContainer()
        let publicDatabase = CKContainer.defaultContainer().privateCloudDatabase
        let predicate = NSPredicate(value: true)
        let sort = NSSortDescriptor(key: "creationDate", ascending: false)
        let query = CKQuery(recordType: "Members", predicate: predicate)
        query.sortDescriptors = [sort]
        publicDatabase.performQuery(query, inZoneWithID: nil, completionHandler: {
            results, error in
            if error == nil {


                self.members = results as! [CKRecord]

                println(self.members)



            } else {
                println(error)
            }
        }) }

要解决这个问题,我必须通过Web DashBoard设置Metadatas索引,但我想知道我是否可以通过代码设置Metadatas索引?

如果有,请给我一些代码示例。

感谢您的所有答案。

1 个答案:

答案 0 :(得分:5)

抱歉,无法从代码中设置索引。您必须在CloudKit仪表板中执行此操作。