gpt4 book ai didi

ios - URLSession.shared.dataTask 中带有 JSON 和字典的 Swift 3 编译器错误

转载 作者:行者123 更新时间:2023-11-28 12:38:33 26 4
gpt4 key购买 nike

在此特定应用代码的先前问题在帮助下“解决”之后,此代码出现了一个新问题:

var properties: [String] = []
var unsortedDetails: [String] = []
var contacts: [[String]] = []
var propertySorting: [(key: String, ind: String, link: Bool)] = []
var autolinks: [Bool] = []

并且,在 viewDidLoad 函数中:

let contactsRequest = URLRequest(url: URL(string: "https://script.google.com/macros/s/AKfycbxOLElujQcy1-ZUer1KgEvK16gkTLUqYftApjNCM_IRTL3HSuDk/exec?id=" + ID + "&sheet=" + Industry.replacingOccurrences(of: " ", with: "+", options: NSString.CompareOptions.literal, range: nil))!)

let contactsTask = URLSession.shared.dataTask(with: contactsRequest as URLRequest)
{(data, response, error) in
do {
let jsonResult: Dictionary = try JSONSerialization.jsonObject(with: data!, options: []) as! [String : Any]

let results = jsonResult[self.Industry] as! [[String : Any]]

for key in results[0].keys {
self.propertySorting.append(key: (key as? String)!, ind: results[0].value(forKey: key as! String) as! String, link: results[1].value(forKey: key as! String) as! String != "X")
}
self.propertySorting.sort(by: {Int($0.ind) < Int($1.ind)})

for property in self.propertySorting {
self.properties.append(property.key)
self.autolinks.append(property.link)
}

for contact in results {
self.contacts.append([])
for key in self.properties {
self.contacts[self.contacts.count-1].append(contact.value(forKey: key) as! String)
}
}

DispatchQueue.main.async(execute: {
let listController = self.viewControllers[0] as! ListController

listController.properties = self.properties
listController.contacts = self.contacts
listController.autolinks = self.autolinks

listController.tableView.reloadData()
})

} catch {
print("FATAL ERROR")
}
}

contactsTask.resume()

现在遇到的问题是:Extra argument 'ind' in call 当调用 propertySorting.append(...) 时,如果删除此(以前工作的)ind 部分,将返回相同的错误对于链接

最佳答案

代替 NSArrayNSDictionary 使用 Swift 原生 ArrayDictionary 并使用 keysDictionary 获取所有键的数组。

let jsonResult: Dictionary = try JSONSerialization.jsonObject(with: data!, options: []) as! [String : Any]
let results = jsonResult[self.Industry] as! [[String : Any]]

for key in results[0].keys {

}

注意:无需对 Swift 原生类型对象使用 .mutableContainers 选项。

关于ios - URLSession.shared.dataTask 中带有 JSON 和字典的 Swift 3 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40146651/

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