Nilsymbol
Nilsymbol

Reputation: 525

NSUserDefaults setObject:forKey: very time expensive

While profiling on the simulator, I noticed that every time I save an NSNumber in in NSUserDefaults it takes a long time, about 600 ms per instance. Is this normal? I have around 5 of these objects I need to save, so that means in total it takes 3000ms which is a long time.

I am using the following line:

[[NSUserDefaults standardUserDefaults] setObject:object forKey:@"key"];

Upvotes: 0

Views: 199

Answers (1)

gnasher729
gnasher729

Reputation: 52622

How much stuff is in your preferences? User preferences is not a database. There's a limit to what you should store there. And I hope you realise that you don't have to synchronise immediately after storing each single item to preferences, so storing five items shouldn't take longer than storing one.

Upvotes: 1

Related Questions