Transformable.swift
1.54 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Transformable.swift
// HandyJSON
//
// Created by zhouzhuo on 15/07/2017.
// Copyright © 2017 aliyun. All rights reserved.
//
import Foundation
public protocol _Transformable: _Measurable {}
extension _Transformable {
static func transform(from object: Any) -> Self? {
if let typedObject = object as? Self {
return typedObject
}
switch self {
case let type as _ExtendCustomBasicType.Type:
return type._transform(from: object) as? Self
case let type as _BuiltInBridgeType.Type:
return type._transform(from: object) as? Self
case let type as _BuiltInBasicType.Type:
return type._transform(from: object) as? Self
case let type as _RawEnumProtocol.Type:
return type._transform(from: object) as? Self
case let type as _ExtendCustomModelType.Type:
return type._transform(from: object) as? Self
default:
return nil
}
}
func plainValue() -> Any? {
switch self {
case let rawValue as _ExtendCustomBasicType:
return rawValue._plainValue()
case let rawValue as _BuiltInBridgeType:
return rawValue._plainValue()
case let rawValue as _BuiltInBasicType:
return rawValue._plainValue()
case let rawValue as _RawEnumProtocol:
return rawValue._plainValue()
case let rawValue as _ExtendCustomModelType:
return rawValue._plainValue()
default:
return nil
}
}
}