SHARE
TWEET

Untitled

a guest Jun 19th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// CodingKeyのマッピングを動的に切り替える
  2. protocol CodingKeyMapper {
  3.     static var mapper: [String: S<Self>.CodingKeys] { get }
  4. }
  5. extension CodingKeyMapper {
  6.     static var mapper: [String: S<Self>.CodingKeys] { return [:] }
  7.  
  8.     static func key(_ stringValue: String) -> S<Self>.CodingKeys? {
  9.         return mapper[stringValue]
  10.     }
  11.     static func stringValue(_ key: S<Self>.CodingKeys) -> String {
  12.         return mapper.first { $0.value == key }?.key ?? String(describing: key)
  13.     }
  14. }
RAW Paste Data
Top