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
.NSUserDefaults
persist 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'sapplicationWillResignActive
method to ensure that the values are cleared when the app is moved to the background.While an
NSCache
is a key/value store similar to a dictionary, your app will clear theNSCache
if it receives any low memory warnings. Only store non-critical (re-creatable) data in anNSCache
.