Re: debugging a static variable
Re: debugging a static variable
- Subject: Re: debugging a static variable
- From: j o a r <email@hidden>
- Date: Sun, 20 Jun 2004 18:50:24 +0200
I would probably have created a class accessor method for this type of
variable. Something like this:
+ (NSMutableDictionary *) modifications
{
static NSMutableDictionary *myModifications = nil;
if (myModifications == nil)
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:
@"modifications" ofType: @"plist"];
myModifications = [[NSMutableDictionary alloc]
initWithContentsOfFile: aFile];
if (myModifications == nil)
{
NSLog(@"Failed to create dictionary for file at path: %@", filePath);
}
}
return myModifications;
}
In this way you hide the actual variable, and make sure that it's
initialized before used.
You can print information about the static variable in GDB by simply
typing "po myDict" in the debugger console - even if it's not listed
among the local variables.
j o a r
On 2004-06-20, at 17.12, Koen van der Drift wrote:
>
I have declared a static variable that can be used by all instances of
>
the same class:
>
>
static NSMutableDictionary *myDict = nil;
>
>
@implementation MyObject
>
>
- (id)init
>
{
>
if ( self = [super init] )
>
{
>
if ( ! myDict )
>
{
>
id aFile = [[NSBundle mainBundle]
>
pathForResource:@"modifications" ofType:@"plist"];
>
NSLog(@"aFile is %@", aFile);
>
[self setMyDict: [[NSMutableDictionary alloc]
>
initWithContentsOfFile: aFile]];
>
}
>
}
>
}
>
>
>
What happens is that every time init gets called, myDict is nil, so
>
the part in brackets is called every time. I know that the dicttionary
>
is created with the right contents, because [self setMyDict: ] gets
>
called. But apparently it is not preserved. I tried to debug this, but
>
I do not see myDict listed in the debugger's variable pane. Is there a
>
way that I can track static variables in the debugger?
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.