Blame view

Pods/HandyJSON/Source/EnumType.swift 755 Bytes
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  //
  //  EnumType.swift
  //  HandyJSON
  //
  //  Created by zhouzhuo on 16/07/2017.
  //  Copyright © 2017 aliyun. All rights reserved.
  //
  
  import Foundation
  
  public protocol _RawEnumProtocol: _Transformable {
  
      static func _transform(from object: Any) -> Self?
      func _plainValue() -> Any?
  }
  
  extension RawRepresentable where Self: _RawEnumProtocol {
  
      public static func _transform(from object: Any) -> Self? {
          if let transformableType = RawValue.self as? _Transformable.Type {
              if let typedValue = transformableType.transform(from: object) {
                  return Self(rawValue: typedValue as! RawValue)
              }
          }
          return nil
      }
  
      public func _plainValue() -> Any? {
          return self.rawValue
      }
  }