【发布时间】:2015-07-02 18:25:26
【问题描述】:
我不知道为什么,但是当我尝试将 CKRecord 保存在我的数据库中时,我的应用程序不断崩溃,并且我收到此错误消息,“以未捕获的 CKException 类型的异常终止。”任何输入将不胜感激。这是我的代码:
func saveCountryMood(countryToSave:String) {
// Create CK record
let newRecord:CKRecord = CKRecord(recordType: realCurrentCountry)
newRecord.setValue(countryToSave, forKey: "Country")
// Save record into public database
if let database = self.publicDatabase {
database.saveRecord(newRecord, completionHandler: { (record:CKRecord!, error:NSError!) -> Void in
// Check for error
if error != nil {
// There was an error
NSLog(error.localizedDescription)
}
else {
// There was no error
dispatch_async(dispatch_get_main_queue()) {
// Refresh table
self.retrieveCountryMoods("")
}
}
})
}
}
【问题讨论】:
-
提供有关异常的更多详细信息。哪条线路导致崩溃?错误信息是什么?
-
这一行崩溃:let newRecord:CKRecord = CKRecord(recordType: realCurrentCountry)
-
确切的错误信息如下:libc++abi.dylib: terminating with uncaught exception of type CKException
-
错误信息一定有更多内容。
-
啊,你是对的,我的错在这里----由于未捕获的异常'CKException'而终止应用程序,原因:'recordType(美国)包含无效字符'***首先抛出调用堆栈: