@@ -137,8 +137,9 @@ open class Dialog: NSObject {
137
137
@discardableResult
138
138
open func positive( _ title: String ? , handler: ( ( ) -> Void ) ? ) -> Dialog {
139
139
dialogView. positiveButton. title = title
140
- controller. didTapPositiveButtonHandler = { [ unowned self] in
141
- self . delegate? . dialog ? ( self , didTapPositive: self . controller. dialogView. positiveButton)
140
+ controller. didTapPositiveButtonHandler = { [ weak self] in
141
+ guard let strongSelf = self else { return }
142
+ strongSelf. delegate? . dialog ? ( strongSelf, didTapPositive: strongSelf. controller. dialogView. positiveButton)
142
143
handler ? ( )
143
144
}
144
145
return self
@@ -153,8 +154,9 @@ open class Dialog: NSObject {
153
154
@discardableResult
154
155
open func negative( _ title: String ? , handler: ( ( ) -> Void ) ? ) -> Dialog {
155
156
dialogView. negativeButton. title = title
156
- controller. didTapNegativeButtonHandler = { [ unowned self] in
157
- self . delegate? . dialog ? ( self , didTapNegative: self . controller. dialogView. negativeButton)
157
+ controller. didTapNegativeButtonHandler = { [ weak self] in
158
+ guard let strongSelf = self else { return }
159
+ strongSelf. delegate? . dialog ? ( strongSelf, didTapNegative: strongSelf. controller. dialogView. negativeButton)
158
160
handler ? ( )
159
161
}
160
162
return self
@@ -169,8 +171,9 @@ open class Dialog: NSObject {
169
171
@discardableResult
170
172
open func neutral( _ title: String ? , handler: ( ( ) -> Void ) ? ) -> Dialog {
171
173
dialogView. neutralButton. title = title
172
- controller. didTapNeutralButtonHandler = { [ unowned self] in
173
- self . delegate? . dialog ? ( self , didTapNeutral: self . controller. dialogView. neutralButton)
174
+ controller. didTapNeutralButtonHandler = { [ weak self] in
175
+ guard let strongSelf = self else { return }
176
+ strongSelf. delegate? . dialog ? ( strongSelf, didTapNeutral: strongSelf. controller. dialogView. neutralButton)
174
177
handler ? ( )
175
178
}
176
179
return self
@@ -185,8 +188,9 @@ open class Dialog: NSObject {
185
188
@discardableResult
186
189
open func isCancelable( _ value: Bool , handler: ( ( ) -> Void ) ? = nil ) -> Dialog {
187
190
controller. isCancelable = value
188
- controller. didCancelHandler = { [ unowned self] in
189
- self . delegate? . dialogDidCancel ? ( self )
191
+ controller. didCancelHandler = { [ weak self] in
192
+ guard let strongSelf = self else { return }
193
+ strongSelf. delegate? . dialogDidCancel ? ( strongSelf)
190
194
handler ? ( )
191
195
}
192
196
return self
@@ -200,8 +204,9 @@ open class Dialog: NSObject {
200
204
*/
201
205
@discardableResult
202
206
open func shouldDismiss( handler: ( ( DialogView , Button ? ) -> Bool ) ? ) -> Dialog {
203
- controller. shouldDismissHandler = { [ unowned self] dialogView, button in
204
- let d = self . delegate? . dialog ? ( self , shouldDismiss: button) ?? true
207
+ controller. shouldDismissHandler = { [ weak self] dialogView, button in
208
+ guard let strongSelf = self else { return true }
209
+ let d = strongSelf. delegate? . dialog ? ( strongSelf, shouldDismiss: button) ?? true
205
210
let h = handler ? ( dialogView, button) ?? true
206
211
return d && h
207
212
}
@@ -215,8 +220,9 @@ open class Dialog: NSObject {
215
220
*/
216
221
@discardableResult
217
222
open func willAppear( handler: ( ( ) -> Void ) ? ) -> Dialog {
218
- controller. willAppear = { [ unowned self] in
219
- self . delegate? . dialogWillAppear ? ( self )
223
+ controller. willAppear = { [ weak self] in
224
+ guard let strongSelf = self else { return }
225
+ strongSelf. delegate? . dialogWillAppear ? ( strongSelf)
220
226
handler ? ( )
221
227
}
222
228
return self
@@ -229,10 +235,11 @@ open class Dialog: NSObject {
229
235
*/
230
236
@discardableResult
231
237
open func didDisappear( handler: ( ( ) -> Void ) ? ) -> Dialog {
232
- controller. didDisappear = { [ unowned self] in
233
- self . delegate? . dialogDidDisappear ? ( self )
238
+ controller. didDisappear = { [ weak self] in
239
+ guard let strongSelf = self else { return }
240
+ strongSelf. delegate? . dialogDidDisappear ? ( strongSelf)
234
241
handler ? ( )
235
- self . controller. dialog = nil
242
+ strongSelf . controller. dialog = nil
236
243
}
237
244
return self
238
245
}
0 commit comments