gpt4 book ai didi

ios - cloudkit saverecord 方法使应用程序崩溃

转载 作者:行者123 更新时间:2023-11-28 09:15:57 24 4
gpt4 key购买 nike

仅供引用,我正在关注这个tutorial

以下方法使我的应用程序在模拟器和设备 (5S) 中崩溃。崩溃发生在“publicDatabase!”行。

我收到以下一般错误

fatal error :在展开可选值时意外发现 nil

@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 上,它将是 nil,因为您可能没有初始化它。

在提供的代码中,没有与publicDatabase初始化相关的代码。因此,请在使用前验证您是否对其进行了初始化。

关于ios - cloudkit saverecord 方法使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27698639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com