override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.global().async(execute: {
print("teste")
print("main thread")
self.getWeather(city: "Minsk")
print("Hello")
})
print("working")
}
func getWeather(city: String) {
let cityEscaped = city.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed)
let path = "http://samples.openweathermap.org/data/2.5/weather?q=Minsk&appid=..." // appid removed for the sake of privacy
let url = URL(string: path)
let session = URLSession.shared
let task = session.dataTask(with: url!) { (data: Data?, response: URLResponse?, error: Error?) in
let json = JSON(data!)
let lon = json["coord"]["lon"].double
let lat = json["coord"]["lat"].double
let temp = json["main"]["temp"].double
let name = json["name"].string
let desc = json["weather"][0]["description"].string
print("Lat: \(lat!) lon:\(lon!) temp: \(temp!) city: \(name!)")
}
task.resume()
}
이의 시작 부분에 인쇄 라인 ("위도! : (LAT) 경도 :! (론) 온도 :! (온도) 도시 :! (이름)")하게 수행 할 수 있습니다 무엇
코드의 지속적인 실행 후? 당신이 getWeather
완료 후 뭔가를하려는 경우DispatchQueue.main.sync 신속
귀하의 질문을 번역 ... –
당신은 그것을 다운로드 첫 번째 인쇄 결과를 원하는가? –
는 "안녕하세요", "위도 경도"후하게 할을 의미합니까? –