跳到主要內容

發表文章

目前顯示的是 10月, 2020的文章

iOS json Decodable

  不知道做了什麼,但先留著 protocol DecodableDefaultSource {     associatedtype Value: Decodable     static var defaultValue: Value { get } } enum DecodableDefault {} extension DecodableDefault {     @propertyWrapper     struct Wrapper<Source: DecodableDefaultSource > {         typealias Value = Source . Value         var wrappedValue = Source.defaultValue     } } extension DecodableDefault . Wrapper : Decodable {     init (from decoder: Decoder ) throws {         let container = try decoder.singleValueContainer()         wrappedValue = try container.decode(Value. self )     } } extension KeyedDecodingContainer {     func decode<T>( _ type: DecodableDefault . Wrapper < T >.Type,                    forKey key: Key ) throws -> DecodableDefault . ...