Re: observing dealloc
Re: observing dealloc
- Subject: Re: observing dealloc
- From: Ken Tozier <email@hidden>
- Date: Tue, 29 May 2007 03:27:51 -0400
Found a simpler and more powerful way to add the globals code, an
NSObject category. I haven't tackled thread safety but it's an
interesting start and eliminates the need for subclassing to add the
functionality. I did some tests on some of my existing classes and it
seems to work
@interface NSObject (GlobalExtensions)
+ (void) initGlobals;
+ (BOOL) globalsInitialized;
+ (void) setGlobal:(id) inObj
forKey:(NSString *) inKey;
+ (id) globalForKey:(NSString *) inKey;
- (id) globalForKey:(NSString *) inKey;
@end
@implementation NSObject (GlobalExtensions)
NSMutableDictionary *gNSObjectGlobals = nil;
+ (void) initGlobals
{
if (gNSObjectGlobals == nil)
gNSObjectGlobals = [[NSMutableDictionary dictionary] retain];
}
+ (BOOL) globalsInitialized
{
return (gNSObjectGlobals == nil) ? NO : (([gNSObjectGlobals count]
== 0) ? NO : YES) ;
}
+ (void) setGlobal:(id) inObj
forKey:(NSString *) inKey
{
// make sure globals are initialized
[self initGlobals];
// add object to global list
[gNSObjectGlobals setObject: inObj forKey: inKey];
}
+ (id) globalForKey:(NSString *) inKey
{
return [gNSObjectGlobals objectForKey: inKey];
}
- (id) globalForKey:(NSString *) inKey
{
return [gNSObjectGlobals objectForKey: inKey];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden