1

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:@"嗨!"];
Kex
  • 8,023
  • 9
  • 56
  • 129

1 Answers1

1

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).

  • The dictionary is stored in a property after it is init. However the object is only created when it's needed, for a few of the view controllers I am using. – Kex Mar 13 '15 at 17:13
  • then if you don't have any heavy code that creates the dictionary content it's faster to create it in code then loading it from disk, but my guess is that you won't notice any difference in the app if the dictionary contents are lightweight – Karim Sallam Mar 13 '15 at 17:15
  • What's classed as heavy code? I have edited my question with an example of the objects I am using. Just objects that contain 3 NSStrings and an NSArray. The dictionary will have around 40-60 of these. – Kex Mar 13 '15 at 17:19
  • Something that takes long computational time like looping through long array. Based on the example it's faster to create it in the code and also less code to deal with! – Karim Sallam Mar 13 '15 at 17:20
  • Okay, I won't archive it then. thanks for your answer – Kex Mar 13 '15 at 17:23