@@ -8,13 +8,6 @@ import func WinSDK.MessageBoxW
8
8
import let WinSDK. MB_OK
9
9
import struct WinSDK. UINT
10
10
11
- private extension Button {
12
- convenience init ( frame: Rect = . zero, title: String ) {
13
- self . init ( frame: frame)
14
- setTitle ( title, forState: . normal)
15
- }
16
- }
17
-
18
11
private extension Label {
19
12
convenience init ( frame: Rect , title: String ) {
20
13
self . init ( frame: frame)
@@ -32,7 +25,10 @@ final class UICatalog: ApplicationDelegate, SceneDelegate {
32
25
33
26
lazy var button : Button =
34
27
Button ( frame: Rect ( x: 72.0 , y: 4.0 , width: 96.0 , height: 32.0 ) ,
35
- title: " Press Me! " )
28
+ primaryAction: Action ( title: " Press Me! " ) { _ in
29
+ MessageBoxW ( nil , " Swift/Win32 Demo! " . wide,
30
+ " Swift/Win32 MessageBox! " . wide, UINT ( MB_OK) )
31
+ } )
36
32
37
33
lazy var checkbox : Switch =
38
34
Switch ( frame: Rect ( x: 4.0 , y: 40.0 , width: 256.0 , height: 24.0 ) )
@@ -111,9 +107,6 @@ final class UICatalog: ApplicationDelegate, SceneDelegate {
111
107
112
108
self . label. font = Font ( name: " Consolas " , size: 10 ) !
113
109
114
- self . button. addTarget ( self , action: UICatalog . pressMe ( _: ) ,
115
- for: . primaryActionTriggered)
116
-
117
110
self . checkbox. title = " Check me out "
118
111
119
112
self . textfield. text = " Introducing Swift/Win32 "
@@ -159,11 +152,6 @@ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deseru
159
152
print ( " Goodbye cruel world! " )
160
153
}
161
154
162
- private func pressMe( _: Button ? ) {
163
- MessageBoxW ( nil , " Swift/Win32 Demo! " . wide,
164
- " Swift/Win32 MessageBox! " . wide, UINT ( MB_OK) )
165
- }
166
-
167
155
private func stepperValueDidChange( _ stepper: Stepper ) {
168
156
self . stepperLabel. text = String ( Int ( stepper. value) )
169
157
self . tableview. reloadData ( )
@@ -179,8 +167,11 @@ extension UICatalog: TableViewDataSource {
179
167
public func tableView( _ tableView: TableView ,
180
168
cellForRowAt indexPath: IndexPath ) -> TableViewCell {
181
169
let cell = TableViewCell ( style: . default, reuseIdentifier: nil )
182
- cell. addSubview ( Button ( frame: Rect ( x: 0 , y: 0 , width: 80 , height: 32 ) ,
183
- title: " Button \( indexPath. row) " ) )
170
+
171
+ let button : Button = Button ( frame: Rect ( x: 0 , y: 0 , width: 80 , height: 32 ) )
172
+ button. setTitle ( " Button \( indexPath. row) " , forState: . normal)
173
+ cell. addSubview ( button)
174
+
184
175
return cell
185
176
}
186
177
}
0 commit comments