9
9
import UIKit
10
10
import Net
11
11
import Moya
12
+ import Kommander
12
13
13
14
class ViewController : UIViewController {
14
15
15
- let net : Net = NetURLSession ( )
16
+ let net : Net = NetURLSession . shared
17
+ let kommander : Kommander = . default
16
18
17
19
override func viewDidLoad( ) {
18
20
super. viewDidLoad ( )
@@ -28,7 +30,7 @@ class ViewController: UIViewController {
28
30
print ( " Net error: \( error) " )
29
31
}
30
32
} catch {
31
- print ( " Parse error: \( ( error as! NetError ) . localizedDescription) " )
33
+ print ( " Parse error: \( error. localizedDescription) " )
32
34
}
33
35
}
34
36
@@ -39,7 +41,7 @@ class ViewController: UIViewController {
39
41
print ( type ( of: object) )
40
42
print ( " Time: \( Date ( ) . timeIntervalSince ( date) ) " )
41
43
} catch {
42
- print ( " Error: \( ( error as! NetError ) . localizedDescription) " )
44
+ print ( " Error: \( error. localizedDescription) " )
43
45
}
44
46
45
47
// Moya
@@ -54,16 +56,16 @@ class ViewController: UIViewController {
54
56
}
55
57
56
58
// Kommander
57
- net. data ( request) . execute ( onSuccess: { object in
59
+ net. data ( request) . execute ( by : kommander , onSuccess: { object in
58
60
print ( object)
59
61
} ) { error in
60
- print ( " Error: \( ( error as! NetError ) . localizedDescription) " )
62
+ print ( " Error: \( String ( describing : error ? . localizedDescription) ) " )
61
63
}
62
64
63
- net. data ( request) . executeDecoding ( onSuccess: { object in
65
+ net. data ( request) . executeDecoding ( by : kommander , onSuccess: { object in
64
66
print ( object as Article )
65
67
} ) { error in
66
- print ( " Error: \( ( error as! NetError ) . localizedDescription) " )
68
+ print ( " Error: \( String ( describing : error ? . localizedDescription) ) " )
67
69
}
68
70
69
71
// Decode
@@ -77,7 +79,7 @@ class ViewController: UIViewController {
77
79
print ( " Net error: \( error) " )
78
80
}
79
81
} catch {
80
- print ( " Parse error: \( ( error as! NetError ) . localizedDescription) " )
82
+ print ( " Parse error: \( error. localizedDescription) " )
81
83
}
82
84
}
83
85
0 commit comments