Samet DEDE
Samet DEDE

Reputation: 1621

Using NSUserDefaults too much

I'm using NSUserDefaults very extensively. I'm saving inside NSUserDefaults many arrays of information about user, and using them later at another view.

My question is, is this a wrong approach? or this can be a problem at sending to AppStore?

Thank you..

Upvotes: 3

Views: 2332

Answers (5)

Dave
Dave

Reputation: 12206

Here's a useful thread. Essentially, go to your project folder and look at the pList file size.

The responses I found helpful were to go to your project file and look at the plist file size:

5 objects is almost nothing. You'll be fine!


On my machine, I have about 28 megs of data in my user defaults. That's not causing any problems at all.


From general programming experience with arrays I would guess performance starts to rapidly decay when you get into 1000’s, depending on element size. Therefore in a program I wouldn’t have an issue storing a couple of hundred elements. This said I would probably start using a sqlite3 database or coredata, sooner rather than later if I were you.

Upvotes: 0

Legolas
Legolas

Reputation: 12325

You wont get reject from the App Store, but its not really good practice to do it. Consider using "Core-data" for storing results and values. And little NSNotifications and NSUserDefaults for communicating between viewControllers.

If you are using NSUserDefaults mainly for communication between different VC's , I would suggest using Delegates ( Message Passing (or) CallBacks )

Upvotes: 1

ggrana
ggrana

Reputation: 2335

Yes it is a wrong approach, but I do not believe that can be a problem to you when you send it to the AppStore.

What you probably have to do is add some configuration files and you manage that, or maybe use core data in your project, to give you a more precise answer only knowing your project.

Best regards.

EDIT to add better explanation when use NSUserDefaults

You only wants to use the NSUserDefaults to store configurations, that will be default to the user, like the user favorite color for your background for example.

You do not want to store in the NSUserDefaults, passwords, temporary information, if you are doing a game, you will not store there your ranking, and things like that.

From apple doc

The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved. Applications record such preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaults since they’re commonly used to determine an application’s default state at startup or the way it acts by default.

Upvotes: 3

ilhnctn
ilhnctn

Reputation: 2210

It is not preferred to save too much data in userdefaults. Istead you can use plist or Core Data to store your data(this is a good Core Data Tutorial). And also NSUSerDefaults is difficult to change&remove objects from, so try to use it just to store username&password ect as much as you can.

Upvotes: 1

Conrad Shultz
Conrad Shultz

Reputation: 8808

There's no hard and fast rule about what or how much information can be stored in NSUserDefaults (except that you should never store secure data). You certainly won't get rejected from the App Store unless you abuse NSUserDefaults to the point of causing crashes.

I'm confused by your statement about using in another view, though. NSUserDefaults is intended for persisting small amounts of data across sessions, not to transfer data between objects in an application. If you are using it for the latter you should revisit your application architecture.

Upvotes: 4

Related Questions