-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShowNetworkHUD.swift
More file actions
71 lines (67 loc) · 1.85 KB
/
Copy pathShowNetworkHUD.swift
File metadata and controls
71 lines (67 loc) · 1.85 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// ResultModelType.swift
// Base
//
// Created by ZJaDe on 2018/7/11.
// Copyright © 2018年 ZJaDe. All rights reserved.
//
import UIKit
import RxNetwork
public typealias TaskVC = MessageHUDProtocol & TaskQueueProtocol
public enum ShowNetworkHUD {
case `default`
case hide
case show
case showIn(TaskVC)
}
public extension ShowNetworkHUD {
func showResultSuccessful(_ text: String) {
guard text.isNotEmpty else { return }
switch self {
case .default, .hide:
break
case .show:
HUD.showSuccess(text)
case .showIn(let viewCon):
viewCon.taskQueue.addTask({ [weak viewCon] in
viewCon?.showSuccess(text)
})
}
}
func showResultError(_ error: Error) {
let error = error._mapError()
#if DEBUG
let text: String
switch error {
case let error as NetworkError:
text = error.localizedDescription
default:
text = "请求错误: \(error)\n\(error.localizedDescription)"
logError(text)
assertionFailure("这里不应该走到,因为前面已经处理过")
}
showResultError(text)
#else
/// ZJaDe: 如果返回的error字符串为空则不处理
let errorStr = error.localizedDescription
showResultError(errorStr)
#endif
}
func showResultError(_ text: String) {
guard text.isNotEmpty else { return }
switch self {
case .hide:
break
case .default, .show:
#if DEBUG
HUD.showError(text, duration: 10.0)
#else
HUD.showError(text)
#endif
case .showIn(let viewCon):
viewCon.taskQueue.addTask({ [weak viewCon] in
viewCon?.showError(text)
})
}
}
}