I have a class that uses a NSMutableDictionary
. This dictionary contains between 40-60 objects of a custom class "appStrings". Right now every time I used the class I just init the dictionary calling my initDictionary method and this adds all the objects and keys. Is it better/faster to instead init the NSDictionary
once and save it to file using NSKeyedArchiver
or just call the init method each time? In terms of writing code it makes no difference, I have to init the dictionary at some point even if I save it and never init again. But what about in terms of performance?
edit: example of an object
appMessage *a= [[miaoMEMessage alloc] initWithCode:@"a" replies: [NSArray arrayWithObjects:@"j", @"k", nil] english:@"Hi!" andChineseTrad:@"嗨!"];
In general is always faster to create object then loading them from disk. In your example is faster to create the dictionary in code then loading it from disk (it will have to create the same objects and load from disk).