Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2026-01-13 Frederik Seiffert <frederik@algoriddim.com>

* Headers/Foundation/NSNotification.h:
* Source/NSNotification.m:
* Source/NSNotificationCenter.m:
* Tests/base/NSNotification/basic.m:
Add NSNotification initWithName:object:userInfo: and update
notificationWithName: factories to use it.

2026-01-13 Frederik Seiffert <frederik@algoriddim.com>

* Source/NSProgress.m: Implement NSProgress isIndeterminate property.
Expand Down
10 changes: 7 additions & 3 deletions Headers/Foundation/NSNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ GS_EXPORT_CLASS
@interface NSNotification : NSObject <NSCopying, NSCoding>

/* Creating a Notification Object */
+ (NSNotification*) notificationWithName: (NSString*)name
+ (NSNotification*) notificationWithName: (NSNotificationName)name
object: (id)object;

+ (NSNotification*) notificationWithName: (NSString*)name
+ (NSNotification*) notificationWithName: (NSNotificationName)name
object: (id)object
userInfo: (NSDictionary*)info;

- (instancetype) initWithName: (NSNotificationName)name
object: (id)object
userInfo: (NSDictionary*)userInfo;

/* Querying a Notification Object */

- (NSString*) name;
- (NSNotificationName) name;
- (id) object;
- (NSDictionary*) userInfo;

Expand Down
32 changes: 23 additions & 9 deletions Source/NSNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,23 @@ + (void) initialize
/**
* Create a new autoreleased notification.
*/
+ (NSNotification*) notificationWithName: (NSString*)name
+ (NSNotification*) notificationWithName: (NSNotificationName)name
object: (id)object
userInfo: (NSDictionary*)info
{
return [concreteClass notificationWithName: name
object: object
userInfo: info];
return AUTORELEASE([[concreteClass allocWithZone: NSDefaultMallocZone()]
initWithName: name object: object userInfo: info]);
}

/**
* Create a new autoreleased notification by calling
* +notificationWithName:object:userInfo: with a nil user info argument.
*/
+ (NSNotification*) notificationWithName: (NSString*)name
+ (NSNotification*) notificationWithName: (NSNotificationName)name
object: (id)object
{
return [concreteClass notificationWithName: name
object: object
userInfo: nil];
return AUTORELEASE([[concreteClass allocWithZone: NSDefaultMallocZone()]
initWithName: name object: object userInfo: nil]);
}

/**
Expand Down Expand Up @@ -126,6 +124,22 @@ - (id) init
return self;
}

- (instancetype) initWithName: (NSNotificationName)name
object: (id)object
userInfo: (NSDictionary*)info
{
if ([self class] == abstractClass)
{
NSZone *z = [self zone];

DESTROY(self);
return [[concreteClass allocWithZone: z]
initWithName: name object: object userInfo: info];
}
[self subclassResponsibility: _cmd];
return nil;
}

- (BOOL) isEqual: (id)other
{
NSNotification *o;
Expand All @@ -145,7 +159,7 @@ - (BOOL) isEqual: (id)other
/**
* Returns the notification name.
*/
- (NSString*) name
- (NSNotificationName) name
{
[self subclassResponsibility: _cmd];
return nil;
Expand Down
24 changes: 16 additions & 8 deletions Source/NSNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,25 @@ + (void) initialize
}
}

+ (NSNotification*) notificationWithName: (NSString*)name
+ (NSNotification*) notificationWithName: (NSNotificationName)name
object: (id)object
userInfo: (NSDictionary*)info
{
GSNotification *n;
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithName: name object: object userInfo: info]);
}

n = (GSNotification*)NSAllocateObject(self, 0, NSDefaultMallocZone());
n->_name = [name copyWithZone: [self zone]];
n->_object = TEST_RETAIN(object);
n->_info = TEST_RETAIN(info);
return AUTORELEASE(n);
- (instancetype) initWithName: (NSNotificationName)name
object: (id)object
userInfo: (NSDictionary*)info
{
if ((self = [super init]))
{
_name = [name copyWithZone: [self zone]];
_object = TEST_RETAIN(object);
_info = TEST_RETAIN(info);
}
return self;
}

- (id) copyWithZone: (NSZone*)zone
Expand All @@ -103,7 +111,7 @@ - (void) dealloc
[super dealloc];
}

- (NSString*) name
- (NSNotificationName) name
{
return _name;
}
Expand Down
Loading