diff --git a/YepKit/UserDefaults/YepUserDefaults.swift b/YepKit/UserDefaults/YepUserDefaults.swift index ce976fcd3..16ef0853e 100644 --- a/YepKit/UserDefaults/YepUserDefaults.swift +++ b/YepKit/UserDefaults/YepUserDefaults.swift @@ -61,7 +61,7 @@ final public class Listenable { didSet { setterAction(value) - for listener in listenerSet { + for listener in listeners.values { listener.action(value) } } @@ -70,13 +70,12 @@ final public class Listenable { public typealias SetterAction = (T) -> Void var setterAction: SetterAction - var listenerSet = Set>() + var listeners: [String: Listener] = [:] public func bindListener(_ name: String, action: @escaping Listener.Action) { - removeListenerWithName(name) let listener = Listener(name: name, action: action) - listenerSet.insert(listener) + listeners[name] = listener } public func bindAndFireListener(_ name: String, action: @escaping Listener.Action) { @@ -86,16 +85,11 @@ final public class Listenable { } public func removeListenerWithName(_ name: String) { - for listener in listenerSet { - if listener.name == name { - listenerSet.remove(listener) - break - } - } + listeners[name] = nil } public func removeAllListeners() { - listenerSet.removeAll(keepingCapacity: false) + listeners.removeAll(keepingCapacity: false) } public init(_ v: T, setterAction action: @escaping SetterAction) {