@objcMembers
public class MyResponse: NSObject, Codable {
public let id: String?
public let context: String?
public let results: [MyResult]?
}
在类扩展中从数据中解析 MyResponse 的正确方法是什么?
我尝试了以下操作,但出现错误“无法赋值:‘self’是不可变的。无法将‘MyResponse’类型的值赋值给‘Self’类型。”
extension MyResponse {
public convenience init(data: Data) throws {
self = try JSONDecoder().decode(MyResponse.self, from: data)
}
}