I am working with an iOS app that will require the user to configure part of the app and that configuration must be saved in the event the user turns on/off a part of the app. Once the app is backgrounded, the users-configuration must be removed for security purposes.
My question is what is the best way to save primarily strings and NSIntegers temporarily and then removing them when the time comes.
NSUserDefaults
NSCache
I have looked into both and am unable to come up with any solid conclusions. Is there another way that I am missing that might be better?
Thanks! -Brian
If you only want your settings to be available while your app is in the foreground, don't store them in
NSUserDefaults.NSUserDefaultspersist between app launches and are removed when the user deletes the app.For temporary storage, consider storing key/value pairs in a simple
NSMutableDictionary. Clear the dictionary in the application delegate'sapplicationWillResignActivemethod to ensure that the values are cleared when the app is moved to the background.While an
NSCacheis a key/value store similar to a dictionary, your app will clear theNSCacheif it receives any low memory warnings. Only store non-critical (re-creatable) data in anNSCache.