Skip to content

Commit

Permalink
fixed multiple actions on control closures
Browse files Browse the repository at this point in the history
  • Loading branch information
mmackh committed Apr 29, 2023
1 parent 7c0929d commit fa34a1e
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions Sources/BaseComponents/UIKit Helpers/ControlClosures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ import UIKit

@objc
fileprivate class ClosureContainer: NSObject {
static var closureCounter: Int = 10
var closureControl: ((UIControl)->())?
var closureGesture: ((UIGestureRecognizer)->())?
var closureBarButtonItem: ((UIBarButtonItem)->())?
weak var owner: AnyObject?

var id: String

override init () {
ClosureContainer.closureCounter += 1
self.id = String(format: "closure_%i",ClosureContainer.closureCounter)
}

@objc func invoke () {
if let owner = owner {
if let control = closureControl {
Expand All @@ -49,7 +41,7 @@ fileprivate class ClosureContainer: NSObject {

fileprivate extension NSObject {
func addClosureContainer(_ closureContainer: ClosureContainer) {
objc_setAssociatedObject(self, &closureContainer.id, closureContainer, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
objc_setAssociatedObject(self, Unmanaged.passUnretained(closureContainer).toOpaque(), closureContainer, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}

Expand Down

0 comments on commit fa34a1e

Please sign in to comment.