此特定应用程序代码的先前问题已解决'在这段代码的帮助下,出现了一个新问题:
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
部分,则会为link
答案 0 :(得分:2)
而不是NSArray
和NSDictionary
使用Swift原生Array
和Dictionary
而使用keys
和Dictionary
来获取所有键的数组。
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
选项。