Skip to content

Instantly share code, notes, and snippets.

@phucnm
Created August 11, 2017 15:45
Show Gist options
  • Select an option

  • Save phucnm/da0fbdec4f9ad1bf4f2704a0193250e3 to your computer and use it in GitHub Desktop.

Select an option

Save phucnm/da0fbdec4f9ad1bf4f2704a0193250e3 to your computer and use it in GitHub Desktop.
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