-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvip.codesnippet
More file actions
123 lines (89 loc) · 2.79 KB
/
vip.codesnippet
File metadata and controls
123 lines (89 loc) · 2.79 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>vip</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>TopLevel</string>
</array>
<key>IDECodeSnippetContents</key>
<string>import UIKit
/**
Implementation
1. Replace 'Sample' to your controller's name
2. Cut 'var output : SampleControllerOutput? /* output */' to your real controller file -> Delete class 'SampleController'
3. Define actions controller needs in protocol SampleControllerOutput
4. Define actions to respond to result in protocol 'SampleInteractorOutput'. For instance: requestSuccess, updateView...
5. Conform actions from 'SampleControllerOutput' in 'extension SampleInteractor'
6. Define actions to update directly to UI to 'SamplePresenterOutput'
7. Conform actions from 'SampleInteractorOutput'
8. Conform actions and update UI
*/
// 2
class SampleController: knController {
var output : SampleControllerOutput?
}
// 3
protocol SampleControllerOutput: class {
func requestFromController()
}
// 4
protocol SampleInteractorOutput: class {
func requestComplete()
}
// 5
extension SampleInteractor: SampleControllerOutput {
func requestFromController() {
/* create worker and let it execute */
}
}
// 6 - Define protocol to update directly to UI
protocol SamplePresenterOutput: class {
func updateView()
}
// 7: Convert Model to View Model to update UI
extension SamplePresenter: SampleInteractorOutput {
func requestComplete() {
output?.updateView()
}
}
// 8 - Update UI
extension SampleController: SamplePresenterOutput {
func updateView() {
}
}
class SampleInteractor {
var output: SampleInteractorOutput?
}
class SamplePresenter {
weak var output: SamplePresenterOutput?
}
//MARK: Configuration
class SampleConfiguration /* called in viewDidLoad */ {
static let shared = SampleConfiguration()
func configure(viewController: SampleController) {
// Presenter
let presenter = SamplePresenter()
presenter.output = viewController
// Interactor
let interactor = SampleInteractor()
interactor.output = presenter
// View controller
viewController.output = interactor
}
}
</string>
<key>IDECodeSnippetIdentifier</key>
<string>298EA13E-11B9-4802-843A-60EE9AD7F7AD</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Swift</string>
<key>IDECodeSnippetTitle</key>
<string>VIP Architecture</string>
<key>IDECodeSnippetUserSnippet</key>
<true/>
<key>IDECodeSnippetVersion</key>
<integer>2</integer>
</dict>
</plist>