Brian
Brian

Reputation: 733

iOS Saving User Configuration

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

Upvotes: 0

Views: 226

Answers (1)

Marcus Adams
Marcus Adams

Reputation: 53870

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's applicationWillResignActive 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 the NSCache if it receives any low memory warnings. Only store non-critical (re-creatable) data in an NSCache.

Upvotes: 1

Related Questions