@@ -62,15 +62,15 @@ extension UIControl {
62
62
63
63
set {
64
64
objc_setAssociatedObject ( self , & associatedEventHandle, newValue,
65
- objc_AssociationPolicy. OBJC_ASSOCIATION_RETAIN_NONATOMIC)
65
+ objc_AssociationPolicy. OBJC_ASSOCIATION_RETAIN_NONATOMIC)
66
66
}
67
67
}
68
68
69
69
/// Adds a closure for a particular event to an internal dispatch table.
70
70
///
71
71
/// - parameter controlEvents: A bitmask specifying the control events for which the action message is
72
72
/// sent.
73
- /// - parameter handler: A block representing an action message, with an argument for the sender.
73
+ /// - parameter handler: A closure representing an action message, with an argument for the sender.
74
74
public func addEventHandler( forControlEvents controlEvents: UIControlEvents ,
75
75
handler: @escaping LKControlHandler )
76
76
{
@@ -99,8 +99,20 @@ extension UIControl {
99
99
self . events ? [ event] = nil
100
100
for wrapper in wrappers {
101
101
self . removeTarget ( wrapper, action: #selector( ControlWrapper . invoke ( _: ) ) ,
102
- for: UIControlEvents ( rawValue: event) )
102
+ for: UIControlEvents ( rawValue: event) )
103
103
}
104
104
}
105
105
}
106
+
107
+ /// Convenience function for setting a control's handler. Removes all other handlers for the provided
108
+ /// events.
109
+ ///
110
+ /// - parameter controlEvents: A bitmask specifying the control events that the handler will replace.
111
+ /// - parameter handler: A closure representing an action message, with an argument for the sender.
112
+ public func setEventHandler( forControlEvents controlEvents: UIControlEvents ,
113
+ handler: @escaping LKControlHandler )
114
+ {
115
+ self . removeEventHandlers ( forControlEvents: controlEvents)
116
+ self . addEventHandler ( forControlEvents: controlEvents, handler: handler)
117
+ }
106
118
}
0 commit comments