宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
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
    }
}