这是我第一次尝试使用方法 setValuesForKeys ,出于某种原因,我一直在绊倒错误,如下所述:
setValue:forUndefinedKey:]:此类不是键值 符合编码的密钥类型。
我在这里经历了几个相关问题,但无济于事。这是我的代码:
class ResumeCategory: NSObject {
var name: String?
var resumes: [Resume]?
static func getJSON() {
let urlString = "https://api.letsbuildthatapp.com/appstore/featured"
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, _, error) in
DispatchQueue.main.async {
if let error = error {
print("Failed to get data from URL: ", error)
return
}
guard let data = data else { return }
do {
let json = try JSONSerialization.jsonObject(with: data, options: []) as! NSDictionary
print(json["categories"]!)
var resumeCategories = [ResumeCategory]()
for dict in json["categories"] as! [[String: Any]] {
let resumeCategory = ResumeCategory()
resumeCategory.setValuesForKeys(dict)
resumeCategories.append(resumeCategory)
}
} catch let error {
print("Failed to parse server response: ", error)
}
}
}.resume()
}