Created
May 7, 2020 13:02
-
-
Save loganwright/d78311d2f80bd8d2a24478aae70b8783 to your computer and use it in GitHub Desktop.
Swift Encodable Dont Encode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct DontEncode<T: Codable> { | |
var wrappedValue: T | |
} | |
extension DontEncode: Codable { | |
init(from decoder: Decoder) throws { | |
self.wrappedValue = try T(from: decoder) | |
} | |
func encode(to encoder: Swift.Encoder) throws { | |
fatalError("this propertys will not encode") | |
} | |
} | |
extension KeyedEncodingContainer { | |
mutating func encode<T>( | |
_ value: DontEncode<T>, | |
forKey key: KeyedEncodingContainer<K>.Key) throws where T: Encodable { | |
// ignore | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment