Should I keep the rows returned by NSLocalizedString ()?

I am working on an iPhone application that we localize in English and Japanese for our initial release. We often call NSLocalizedString()to load the appropriate localized string for display. As a rule, is it better to save localized strings in instance variables the next time we need them, or am I micro-optimized here, and I just have to reload the string every time I need it?

+5
source share
3 answers

This is one of the "it depends" answers.

Calling NSLocalizedString involves performing a search in a bundle. These searches are fairly quick, but not free. Whether this return value should be cached or just using the NSLocalizedString call will depend on how it is used.

  • If you go back to a text field of something like UILabel or UITableViewCell, then the search will only happen when you first set the property.

  • If you use it in a drawRect call, then the search will be when your opinion should be which may be often, infrequently or never.

  • If you use it in the game’s user interface, the screen is redrawn every frame, then for several user interface elements these searches can occur hundreds of times per second.

I would say that for something like # 3 you should start by caching the results.

, , , , , . NSLocalizedString, .

+7

Micro-. , , . 3, Shark ( ), .

+7

, . NSLocalizedString (key, comment) - ,

[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]

, , , . , , Shark Instruments , .

+1

All Articles