gpt4 book ai didi

ios - 线程 1 : exc_bad_instruction(code=exc_i386_invop, 子代码=0x0)错误

转载 作者:行者123 更新时间:2023-11-30 13:44:04 29 4
gpt4 key购买 nike

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.


}
@IBAction func onbutton(sender: UIButton) {

inputarea.text = "Success"
getweatherdata("http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=44db6a862fba0b067b1930da0d769e98")

// UIApplication.sharedApplication().openURL(NSURL(string:"http://www.reddit.com/")!)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func getweatherdata(urlString : String){

let url = NSURL(string: urlString)
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) { (data, response, error) in dispatch_async(dispatch_get_main_queue(),{
self.setLabels(data!)
})
}
task.resume()
}

我正在尝试实现一个简单的天气应用程序,我能够编译代码,但执行后我在函数调用 self 时遇到错误“thread 1: exc_bad_instruction(code=exc_i386_invop,subcode=0x0) error” .setLabels(data!),我检查了url,它返回的数据不是nil。

我有 setLabels 函数,可以提取子数据并显示它,如果有人需要,我将非常乐意提供完整的代码。谢谢

请找到下面的setLabels函数,appname和templ是View中的标签

        func setLabels(weatherdata: NSData){
do {
if let jsonResult = try NSJSONSerialization.JSONObjectWithData(weatherdata, options: []) as? NSDictionary {
print(jsonResult)

if let name = jsonResult["name"] as? String{
appname.text = name
}

if let main = jsonResult["main"] as? String{
//if let temp = main["temp"] as? Double {
//templ.text = String(format: "%.1f",temp)
templ.text = main

}
}
} catch let error as NSError {
print(error.localizedDescription)
}

最佳答案

可能是您未正确解包 JSON 数据。如果输入错误,打开包装时可能会发现 nil。您是否使用 if let 来解析您的 JSON,或者某种 JSON 解析器?您介意发布完整的 setLabels() 函数吗?

关于ios - 线程 1 : exc_bad_instruction(code=exc_i386_invop, 子代码=0x0)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35189862/

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