• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: observing dealloc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: observing dealloc
      • From: glenn andreas <email@hidden>
References: 
 >Re: observing dealloc (From: Erik Buck <email@hidden>)
 >Re: observing dealloc (From: Ken Tozier <email@hidden>)
 >Re: observing dealloc (From: Steve Israelson <email@hidden>)
 >Re: observing dealloc (From: Ken Tozier <email@hidden>)
 >Re: observing dealloc (From: Chris Hanson <email@hidden>)
 >Re: observing dealloc (From: Ken Tozier <email@hidden>)
 >Re: observing dealloc (From: Chris Suter <email@hidden>)
 >Re: observing dealloc (From: Ken Tozier <email@hidden>)

  • Prev by Date: cocoa and ms windows
  • Next by Date: How to read NSComboBox auto-completed string?
  • Previous by thread: Re: observing dealloc
  • Next by thread: Re: observing dealloc
  • Index(es):
    • Date
    • Thread