Created
August 22, 2018 09:49
-
-
Save atdrendel/174c32cb3a6413e1094e6725e6c2a4dd to your computer and use it in GitHub Desktop.
Encoding Dictionary<String, String>
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
extension Dictionary where Key==String, Value==String { | |
struct DictCodingKey: CodingKey { | |
var stringValue: String | |
init(stringValue: String) { | |
self.stringValue = stringValue | |
} | |
var intValue: Int? { return nil } | |
init?(intValue: Int) { return nil } | |
} | |
func encode(to encoder: Encoder) throws { | |
var container = encoder.container(keyedBy: DictCodingKey.self) | |
try self.forEach { (key, value) in | |
try container.encode(value, forKey: DictCodingKey(stringValue: key)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment