Commit 8c4d7eb 1 parent a5d1ba4 commit 8c4d7eb Copy full SHA for 8c4d7eb
File tree 2 files changed +170
-60
lines changed
FranticApparatusDemo/FranticApparatusDemo
2 files changed +170
-60
lines changed Original file line number Diff line number Diff line change @@ -57,29 +57,33 @@ public final class NetworkAPI {
57
57
58
58
fileprivate func parseJSONData( _ data: Data ) -> Promise < NSDictionary > {
59
59
return Promise< NSDictionary> { ( fulfill, reject, isCancelled) in
60
- do {
61
- let object = try JSONSerialization . jsonObject ( with: data, options: [ ] )
62
-
63
- if let dictionary = object as? NSDictionary {
64
- fulfill ( dictionary)
60
+ dispatcher. dispatch {
61
+ do {
62
+ let object = try JSONSerialization . jsonObject ( with: data, options: [ ] )
63
+
64
+ if let dictionary = object as? NSDictionary {
65
+ fulfill ( dictionary)
66
+ }
67
+ else {
68
+ reject ( NetworkError . unexpectedData ( data) )
69
+ }
65
70
}
66
- else {
67
- reject ( NetworkError . unexpectedData ( data ) )
71
+ catch {
72
+ reject ( error )
68
73
}
69
74
}
70
- catch {
71
- reject ( error)
72
- }
73
75
}
74
76
}
75
77
76
78
fileprivate func parseImageData( _ data: Data ) -> Promise < UIImage > {
77
79
return Promise< UIImage> { ( fulfill, reject, isCancelled) in
78
- if let image = UIImage ( data: data) {
79
- fulfill ( image)
80
- }
81
- else {
82
- reject ( NetworkError . unexpectedData ( data) )
80
+ dispatcher. dispatch {
81
+ if let image = UIImage ( data: data) {
82
+ fulfill ( image)
83
+ }
84
+ else {
85
+ reject ( NetworkError . unexpectedData ( data) )
86
+ }
83
87
}
84
88
}
85
89
}
You can’t perform that action at this time.
0 commit comments