我有一个主ViewController和两个孩子。而且在主函数中,我有一个查找所有词的功能,该函数可以找到单词的所有字谜,并应提供它们的总数,但是我得到的数据不在主线程中,所以我无法更改子视图控制器的属性。如何获得?我可以将其打印出来。
func findAll(for word: String) {
let urlString = "http://www.anagramica.com/all/:\(word)"
let url = URL(string: urlString)
let task = URLSession.shared.dataTask(with: url!) { [weak self] (data, response, error) in
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : [String]]
var words = json["all"] ?? [String]()
while words.last?.count ?? 1000 < 3 {
words.popLast()
}
print(words.count)
self!.infoView.maximum = words.count
self!.infoView.updateLabels()
}
catch let error {
print(error)
}
}
task.resume()
}