From a9767cdff7016559638de0933b92127cc1188091 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Tue, 21 Apr 2020 09:16:53 +0100 Subject: [PATCH] Override -hash and -isEqual: so that notifications with the name name, object, and userInfo are considered equal. This is the OSX behavior. --- ChangeLog | 6 ++++++ Source/NSNotification.m | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ChangeLog b/ChangeLog index c3e39f230..3e7f738c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-04-21 Richard Frith-Macdonald + + * Source/NSNotification.m: + Override -hash and -isEqual: so that notifications with the name name, + object, and userInfo are considered equal. This is the OSX behavior. + 2020-04-14 Richard Frith-Macdonald * Headers/GNUstepBase/GSConfig.h.in: diff --git a/Source/NSNotification.m b/Source/NSNotification.m index 73d841765..79ae9412e 100644 --- a/Source/NSNotification.m +++ b/Source/NSNotification.m @@ -110,6 +110,11 @@ static Class concreteClass = 0; [self name], [self object], [self userInfo]]; } +- (NSUInteger) hash +{ + return [[self name] hash] ^ [[self object] hash]; +} + - (id) init { if ([self class] == abstractClass) @@ -122,6 +127,22 @@ static Class concreteClass = 0; return self; } +- (BOOL) isEqual: (id)other +{ + NSNotification *o; + NSObject *v1; + NSObject *v2; + + if (NO == [(o = other) isKindOfClass: [NSNotification class]] + || ((v1 = [self name]) != (v2 = [o name]) && ![v1 isEqual: v2]) + || ((v1 = [self object]) != (v2 = [o object]) && ![v1 isEqual: v2]) + || ((v1 = [self userInfo]) != (v2 = [o userInfo]) && ![v1 isEqual: v2])) + { + return NO; + } + return YES; +} + /** * Returns the notification name. */