Need advice about how to cache text data on iPhone
Could you give me some开发者_如何学Go algorithm or example?
NSUserDefaults
will nicely hold onto snippets of data.
Example:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:tabBarController.view];
if ([[NSUserDefaults standardUserDefaults] integerForKey:kTabIndexKey])
tabBarController.selectedIndex = [[NSUserDefaults standardUserDefaults] integerForKey:kTabIndexKey];
}
- (void)applicationWillTerminate:(UIApplication *)application {
[[NSUserDefaults standardUserDefaults] setInteger:tabBarController.selectedIndex forKey:kTabIndexKey];
}
Persists and loads an integer (your method would be "setString" and "stringForKey", check the docs.)
精彩评论