Skip to content

Commit 1363ec9

Browse files
committed
fixed being able to remove a different notification observation if you try to remove one twice
1 parent ee72b44 commit 1363ec9

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Foundation/NSNotification.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ open class NotificationCenter: NSObject {
160160
let receiverIdentifier: ObjectIdentifier = ObjectIdentifier(observer)
161161

162162
_observersLock.synchronized({
163-
if _observers[notificationNameIdentifier]?[senderIdentifier]?.count == 1 {
163+
_observers[notificationNameIdentifier]?[senderIdentifier]?.removeValue(forKey: receiverIdentifier)
164+
if _observers[notificationNameIdentifier]?[senderIdentifier]?.count == 0 {
164165
_observers[notificationNameIdentifier]?.removeValue(forKey: senderIdentifier)
165-
} else {
166-
_observers[notificationNameIdentifier]?[senderIdentifier]?.removeValue(forKey: receiverIdentifier)
167166
}
168167
})
169168
}

0 commit comments

Comments
 (0)