@@ -14,31 +14,34 @@ public protocol FlutterStandardCodable {
14
14
/// extension for initializing a type from a type-erased value
15
15
public extension AnyFlutterStandardCodable {
16
16
init ( _ any: Any ) throws {
17
- if isNil ( any) {
17
+ guard ! isNil( any) else {
18
18
self = . nil
19
- } else if let bool = any as? Bool {
19
+ return
20
+ }
21
+ switch any {
22
+ case let bool as Bool :
20
23
self = bool ? . true : . false
21
- } else if let int32 = any as? Int32 {
24
+ case let int32 as Int32 :
22
25
self = . int32( int32)
23
- } else if let int64 = any as? Int64 {
26
+ case let int64 as Int64 :
24
27
self = . int64( int64)
25
- } else if let float64 = any as? Double {
28
+ case let float64 as Double :
26
29
self = . float64( float64)
27
- } else if let string = any as? String {
30
+ case let string as String :
28
31
self = . string( string)
29
- } else if let uint8Data = any as? [ UInt8 ] {
32
+ case let uint8Data as [ UInt8 ] :
30
33
self = . uint8Data( uint8Data)
31
- } else if let int32Data = any as? [ Int32 ] {
34
+ case let int32Data as [ Int32 ] :
32
35
self = . int32Data( int32Data)
33
- } else if let int64Data = any as? [ Int64 ] {
36
+ case let int64Data as [ Int64 ] :
34
37
self = . int64Data( int64Data)
35
- } else if let float32Data = any as? [ Float ] {
38
+ case let float32Data as [ Float ] :
36
39
self = . float32Data( float32Data)
37
- } else if let float64Data = any as? [ Double ] {
40
+ case let float64Data as [ Double ] :
38
41
self = . float64Data( float64Data)
39
- } else if let list = any as? [ Any ] {
42
+ case let list as [ Any ] :
40
43
self = try . list( list. map { try AnyFlutterStandardCodable ( $0) } )
41
- } else if let map = any as? [ AnyHashable : Any ] {
44
+ case let map as [ AnyHashable : Any ] :
42
45
self = try . map( map. reduce ( [ : ] ) {
43
46
var result = $0
44
47
try result [ AnyFlutterStandardCodable ( $1. key) ] = AnyFlutterStandardCodable (
@@ -47,13 +50,13 @@ public extension AnyFlutterStandardCodable {
47
50
)
48
51
return result
49
52
} )
50
- } else if let any = any as? FlutterStandardCodable {
53
+ case let any as FlutterStandardCodable :
51
54
self = try any. bridgeToAnyFlutterStandardCodable ( )
52
- } else if let raw = any as? ( any RawRepresentable ) {
55
+ case let raw as any RawRepresentable :
53
56
self = try raw. bridgeToAnyFlutterStandardCodable ( )
54
- } else if let encodable = any as? Encodable {
57
+ case let encodable as Encodable :
55
58
self = try encodable. bridgeToAnyFlutterStandardCodable ( )
56
- } else {
59
+ default :
57
60
throw FlutterSwiftError . notRepresentableAsStandardField
58
61
}
59
62
}
0 commit comments