Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zmian committed Feb 12, 2024
1 parent 3001294 commit 18d46eb
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions Sources/Xcore/Cocoa/Blocks/UIGestureRecognizer+Blocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ extension UIGestureRecognizer: TargetActionBlockRepresentable {
}

extension TargetActionBlockRepresentable where Self: UIGestureRecognizer {
public init(_ handler: @escaping (_ sender: Self) -> Void) {
self.init()
setActionHandler(handler)
}

public func addAction(_ action: @escaping (_ sender: Self) -> Void) {
setActionHandler(action)
}

public func removeAction() {
setActionHandler(nil)
}

/// A Boolean property indicating whether an action handler is attached.
public var hasActionHandler: Bool {
actionHandler != nil
}

private func setActionHandler(_ handler: ((_ sender: Self) -> Void)?) {
guard let handler else {
actionHandler = nil
Expand All @@ -37,26 +55,4 @@ extension TargetActionBlockRepresentable where Self: UIGestureRecognizer {
actionHandler = wrapper
addTarget(wrapper, action: #selector(wrapper.invoke(_:)))
}

/// Add action handler when the item is selected.
///
/// - Parameter action: The block to invoke when the item is selected.
public func addAction(_ action: @escaping (_ sender: Self) -> Void) {
setActionHandler(action)
}

/// Removes action handler from `self`.
public func removeAction() {
setActionHandler(nil)
}

/// A Boolean property indicating whether an action handler is attached.
public var hasActionHandler: Bool {
actionHandler != nil
}

public init(_ handler: @escaping (_ sender: Self) -> Void) {
self.init()
setActionHandler(handler)
}
}

0 comments on commit 18d46eb

Please sign in to comment.