gpt4 book ai didi

ios - 线程 1 EXC_bad_instruction (code=exc_1386_invop subcode=0x0)

转载 作者:行者123 更新时间:2023-11-28 08:26:05 25 4
gpt4 key购买 nike

我对这段代码有疑问。为什么它在“let session”行给我一个错误“Thread 1 EXC_bad_instruction (code=exc_1386_invop subcode=0x0)”?

import Foundation

protocol WeatherServiceDelegate{
func setWeather(weather:Weather)
}

class WeatherService{

var delegate: WeatherServiceDelegate?
func getWeather(city: String){
let path = "http://api.openweathermap.org/data/2.5/weather?q=Boston&"
let url = URL(string: path)

let session = URLSession.shared.dataTask(with: url!) { (data: Data?, respone:URLResponse?,error: Error?) in
print(">>>>>\(data)")
}

session.resume()

最佳答案

如果您“在解包时发现 nil”,则 url 创建不起作用

通常你应该尽可能远离 !s 并使用 if letguard let 来转换它们。在这种情况下,我不确定为什么它会失败,但如果您隔离 url 创建,您可能能够找出问题。

关于ios - 线程 1 EXC_bad_instruction (code=exc_1386_invop subcode=0x0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39951350/

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