This is the extension of UIView to add easily a UiTapGestureRecognizer to uiimageview:
extension UIView {
fileprivate struct AssociatedObjectKeys {
static var tapGestureRecognizer = "MediaViewerAssociatedObjectKey_mediaViewer"
}
fileprivate typealias Action = (() -> Void)?
fileprivate var tapGestureRecognizerAction: Action? {
set {
if let newValue = newValue {
// Computed properties get stored as associated objects
objc_setAssociatedObject(self, &AssociatedObjectKeys.tapGestureRecognizer, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) //Forming 'UnsafeRawPointer' to an inout variable of type String exposes the internal representation rather than the string contents.
}
}
get {
let tapGestureRecognizerActionInstance = objc_getAssociatedObject(self, &AssociatedObjectKeys.tapGestureRecognizer) as? Action //Forming 'UnsafeRawPointer' to an inout variable of type String exposes the internal representation rather than the string contents.
return tapGestureRecognizerActionInstance
}
}
public func addTapGestureRecognizer(action: (() -> Void)?) {
self.isUserInteractionEnabled = true
self.tapGestureRecognizerAction = action
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture))
self.addGestureRecognizer(tapGestureRecognizer)
}
@objc fileprivate func handleTapGesture(sender: UITapGestureRecognizer) {
if let action = self.tapGestureRecognizerAction {
action?()
} else {
print("no action")
}
}
}
But xcode tells me this twice for the set and the get methods: Forming ‘UnsafeRawPointer’ to an inout variable of type String exposes the internal representation rather than the string contents.
What do i have to do to silent it?
I notice that the code works but with this 2 warnings.
Thank u