Ios cloudkit saverecord方法导致应用程序崩溃
仅供参考,我正在关注此事 以下方法使我的应用程序在模拟器和设备中崩溃。崩溃发生在publicDatabase!线路 我得到以下一般性错误 致命错误:在展开可选值时意外发现nilIos cloudkit saverecord方法导致应用程序崩溃,ios,swift,cloudkit,Ios,Swift,Cloudkit,仅供参考,我正在关注此事 以下方法使我的应用程序在模拟器和设备中崩溃。崩溃发生在publicDatabase!线路 我得到以下一般性错误 致命错误:在展开可选值时意外发现nil @IBAction func saveRecord(sender: AnyObject) { if (photoURL == nil) { notifyUser("No Photo", message: "Use the Photo option to choose a photo for th
@IBAction func saveRecord(sender: AnyObject) {
if (photoURL == nil) {
notifyUser("No Photo", message: "Use the Photo option to choose a photo for the record")
return
}
let asset = CKAsset(fileURL: photoURL!)
let myRecord = CKRecord(recordType: "Houses")
myRecord.setObject(addressField.text, forKey: "address")
myRecord.setObject(commentsField.text, forKey: "comment")
myRecord.setObject(asset, forKey: "photo")
publicDatabase!.saveRecord(myRecord, completionHandler:
({returnRecord, error in
if let err = error {
self.notifyUser("Save Error", message:
err.localizedDescription)
} else {
dispatch_async(dispatch_get_main_queue()) {
self.notifyUser("Success",
message: "Record saved successfully")
}
self.currentRecord = myRecord
}
}))
}
有人能提供帮助吗?问题在于publicDatabase,它将为零,因为您可能没有初始化它
在提供的代码中,没有与publicDatabase初始化相关的代码。因此,请在使用之前验证是否已初始化它