在Cloudkit中创建CKRecord?

时间:2015-09-01 18:43:51

标签: swift cloudkit ckrecord

我是CloudKit的新手,我正在尝试为我的公共数据库recordType" UserProfile"创建一条记录。

我认为我的语法在最后一行代码中不正确,因为我收到了错误"无法调用' saveRecord'使用类型的参数列表(CKRecord,(CKRecord!,NSError) - > Void)'

由于我不知道的Swift更新,我收到错误,感谢任何帮助!

var nameRecord = CKRecord(recordType: "UserProfile")
    nameRecord.setValue("Jimmy", forKey: "Name")
    CKContainer.defaultContainer().publicCloudDatabase.saveRecord(nameRecord) { (savedRecord: CKRecord!, error: NSError) -> Void in

    }

1 个答案:

答案 0 :(得分:2)

The error is because you are passing in a closure of type (CKRecord!,NSError) which you should be passing in one of type (CKRecord!,NSError!), or one using explicit optionals rather than implicitly unwrapped optionals.

Try:

var nameRecord = CKRecord(recordType: "UserProfile")
    nameRecord.setValue("Jimmy", forKey: "Name")
    CKContainer.defaultContainer().publicCloudDatabase.saveRecord(nameRecord) { (savedRecord: CKRecord?, error: NSError?) -> Void in

    }