Add userInfo accessor to NSProgress.

This commit is contained in:
Frederik Seiffert 2022-04-29 14:38:35 +02:00 committed by Frederik Seiffert
parent 57eae2e779
commit 8ca4381676
3 changed files with 13 additions and 2 deletions

View file

@ -118,6 +118,7 @@ GS_NSProgress_IVARS;
- (void) setKind: (NSProgressKind)k;
- (void) setUserInfoObject: (id)obj
forKey: (NSProgressUserInfoKey)key;
- (GS_GENERIC_CLASS(NSDictionary,NSProgressUserInfoKey,id) *)userInfo;
// Instance property accessors...
- (void) setFileOperationKind: (NSProgressFileOperationKind)k;

View file

@ -116,7 +116,6 @@ static NSMutableDictionary *__subscribers = nil;
- (void) dealloc
{
RELEASE(internal->_userInfo);
RELEASE(internal->_fileOperationKind);
RELEASE(internal->_kind);
RELEASE(internal->_estimatedTimeRemaining);
@ -345,6 +344,11 @@ static NSMutableDictionary *__subscribers = nil;
[internal->_userInfo setObject: obj forKey: key];
}
- (GS_GENERIC_CLASS(NSDictionary,NSProgressUserInfoKey,id) *)userInfo
{
return AUTORELEASE([internal->_userInfo copy]);
}
// Instance property accessors...
- (void) setFileOperationKind: (NSProgressFileOperationKind)k;
{

View file

@ -6,11 +6,17 @@
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSDictionary *dict = [NSDictionary dictionary];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:@"value" forKey:@"key"];
NSProgress *progress = [[NSProgress alloc] initWithParent: nil
userInfo: dict];
PASS(progress != nil, "[NSProgress initWithParent:userInfo:] returns instance");
PASS_EQUAL([progress userInfo], dict, @"[NSProgress userInfo] returns correct user info");
[progress setUserInfoObject:@"new value" forKey:@"key"];
PASS_EQUAL([[progress userInfo] objectForKey:@"key"], @"new value", @"[NSProgress setUserInfoObject:forKey:] updates user info");
progress = [NSProgress discreteProgressWithTotalUnitCount:100];
PASS(progress != nil, "[NSProgress discreteProgressWithTotalUnitCount:] returns instance");