如何解决我的Swift应用出现错误,但我不知道如何解决?你能帮助我吗?
您好,我的应用程序发生致命错误:意外地发现nil,同时隐式展开了Optional值错误。我了解到选项存在问题。但是我不知道该如何更改,您能帮我吗?
func checkDownloadResponse(_ data:Data){
let dictionary: NSDictionary!=(try? JSONSerialization.jsonObject(with: data,options: JSONSerialization.ReadingOptions.mutableContainers)) as? NSDictionary
let action_str=dictionary.value(forKey: "Action") as! Nsstring
**ERROR Thread 9: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value**
if(action_str == "1"){
let languageDictionary: NSDictionary = ["Action":(dictionary.value(forKey: "Action")! as AnyObject).description,"LanguageLabels":dictionary.value(forKey: "LanguageLabels")!]
let generalDataDictionary: NSDictionary = ["Action":(dictionary.value(forKey: "Action")! as AnyObject).description,"DataSource":dictionary.value(forKey: "ConfigData")!]
}else{
if(dict.value(forKey: "Error") != nil ){
let error_str=dictionary.value(forKey: "Error") as! Nsstring
//code
}else{
//code
}
}
}
这是出错的地方
ref = db.products(category: category.id)
解决方法
要解决id上的展开问题,那么:
if let value = ref {
value = db.products(category: category.id)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。