Reputation: 17553
My app needs to convert between the singular and plural versions of certain words at various moments. I've therefore got a dictionary where the keys are the singular versions and the values are the plural versions.
I'm wondering what the best way is to reinitialize this dictionary when necessary. As I see it, I have two options:
init
method.My guess is that #2 is faster, but doesn't feel very elegant. Ultimately, subclassing NSDictionary seems like the right approach, but once I found out that NSDictionary is actually a class cluster, well, I chose not to do that.
Upvotes: 0
Views: 137
Reputation: 14834
You can serialize/store it to disk with NSKeyedArchiver and read it back with NSKeyedUnarchiver.
Upvotes: 0
Reputation: 9392
Is the dictionary going to be very large? If so, why not just initialize it as an instance variable when your app activates and don't release it. Also, I'm confused by your 2nd option and your comment. You mentioned in your option that you were going to create a wrapper object for a NSDictionary, but then you said you were going to subclass it. I'm not sure if you just got the confused or what, but your 2nd option (By creating a wrapper object with 1 NSDictionary and initializing the values in the init) also seems feasible to me too. Ultimately, any option should be fine as long as it doesn't impact the performance of your app too much.
Upvotes: 1