Avatar
struct E : Error {} enum JSONNullable<T> : Codable { case value(T) case null init(from decoder: Decoder) throws { var sc = try decoder.singleValueContainer() print(71) if sc.decodeNil() { self = .null return } print(72) if let decodableType: Decodable.Type = T.self as? Decodable.Type { print(73) self = .value(try decodableType.init(from: decoder) as! T) } else { print(74) throw E() } } func encode(to encoder: Encoder) throws { switch self { case .value(let anyValue): if let encodableValue = anyValue as? Encodable { try encodableValue.encode(to: encoder) } else { throw E() } case .null: var sc = encoder.singleValueContainer() try sc.encodeNil() } } }
6:49 AM
@tarunon T = String でも print 74 にいっちゃうんだけどなんか前こんな分岐やってたよね