This is my code.
#import "States.h"
@interface States ()
+ (NSString *)statesFilePath;
@end
static NSMutableDictionary *states = nil;
@implementation States
+ (NSString *)statesFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *statesFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:gStatesFile];
return statesFilePath;
}
+ (void)load
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[states release];
NSString *filePath = [[States statesFilePath] retain];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
states = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
} else {
states = [[NSMutableDictionary dictionaryWithObject:[NSNumber numberWithInt:0] forKey:@"ID"] retain];
}
[filePath release];
[pool release];
}
I know store states in a static variant wasn’t a good idea.
But my question is: why load() automatic executed every time when the app starts?
Cause the states is an unassigned static variant, the complier automaticly find a method to init it?
The load function is called whenever a static class is added to the runtime, so whats happening to you is normal behavior, if you want a function to not be called, name it something else
from apple docs