杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
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
    }
}