@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)
}
}