extension Optional where Wrapped: Encodable { public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() switch self { case .none: try container.encodeNil() case .some(let wrapped): try container.encode(wrapped) } } } extension Optional { public func encode(to encoder: Encoder) throws { fatalError() } }
これはダメでしたっけ