Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement