Re: global NSMutableDictionary
Re: global NSMutableDictionary
- Subject: Re: global NSMutableDictionary
- From: Bill Bumgarner <email@hidden>
- Date: Tue, 29 Jul 2008 11:04:45 -0700
On Jul 29, 2008, at 10:57 AM, Nathaniel Gottlieb-Graham wrote:
Why do externs seem to have to be NSStrings? Also, is this even the
right way to go about having a read/write global
NSMutableDictionary? If not, how would I do this?
The variables cannot point to anything that isn't a constant. @"foo
bar" is a constant string and is handled differently by the compiler/
linker. [[NSMutableDictionary dictionary] retain] is not a constant
and, thus, cannot be used to directly initialize a variable at time of
declaration within a global scope.
Instead, you need to initialize the variables as early as needed
within your application.
This could be done in main(). Or it could be done in the +initialize
for a class.
Or you could annotate a function as a constructor. It will run before
main().
static void __InitializeGlobalStuffMan(void) __attribute__
((constructor));
void __InitializeGlobalStuffMan(void) {
myGlobalDictionary = [[NSMutableDictionary alloc] init];
....
}
b.bum
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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