I'm trying to add tap gesture support to UIView via an extension. This is pretty straight forward using Objective-C, but I'm getting the following error when trying to set the void return block on the runtime property.
error: type '() -> Void' does not conform to protocol 'AnyObject'
Here is the computed property:
var tapAction: (() -> Void)? {
get {
objc_getAssociatedObject(self, &AssociatedKeys.SNGLSActionHandlerTapBlockKey)
}
set {
objc_setAssociatedObject(
self,
&AssociatedKeys.SNGLSActionHandlerTapBlockKey,
newValue,
UInt(OBJC_ASSOCIATION_COPY_NONATOMIC)
)
}
}
I've tried to set the tapAction as a typealias
, but still receive the same error.