Alan
Alan

Reputation: 46833

Is Read Access for NSUserDefaults an "expensive" operation?

The title pretty much sums it up, when reading data stored in the NSUserDefaults for an iphone app, are there any performance considerations that need to be made?

Is there anything I'm misssing, or is reading from NSUserDefaults trivial, and can be abused to a developer's heart desire?

Upvotes: 5

Views: 724

Answers (1)

Mihai Fratu
Mihai Fratu

Reputation: 7663

At runtime, you use an NSUserDefaults object to read the defaults that your application uses from a user’s defaults database. NSUserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value. The synchronize method, which is automatically invoked at periodic intervals, keeps the in-memory cache in sync with a user’s defaults database.

As far as the documentation says it's pretty safe to use it as long as you avoid calling the synchronize too often. You can read more details about it here.

Upvotes: 11

Related Questions