Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created May 7, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loganwright/d78311d2f80bd8d2a24478aae70b8783 to your computer and use it in GitHub Desktop.
Save loganwright/d78311d2f80bd8d2a24478aae70b8783 to your computer and use it in GitHub Desktop.
Swift Encodable Dont Encode
@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