Created
August 11, 2017 15:45
-
-
Save phucnm/da0fbdec4f9ad1bf4f2704a0193250e3 to your computer and use it in GitHub Desktop.
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
| class DictionaryKeyTransform: TransformType { | |
| typealias Object = [String] | |
| typealias JSON = [String: Bool] | |
| func transformFromJSON(_ value: Any?) -> [String]? { | |
| guard let v = value as? JSON else { return [String]() } | |
| return Array(v.keys) | |
| } | |
| func transformToJSON(_ value: [String]?) -> [String : Bool]? { | |
| return value?.reduce([String: Bool](), { (result, string) -> [String: Bool] in | |
| var dict = result | |
| dict[string] = true | |
| return dict | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment