Reputation: 8497
Are there any performance or other consequences for setting an object for key in the NSUserDefaults repeatedly?
[self.myDefaults setObject:someObject forKey:someKey];
and/or
anObject = [self.myDefaults objectForKey:someKey];
My loop will repeat approx 100 times within a second, and only last for a few seconds at a time.
I'll only be calling synchronize
after the loop is finished.
Upvotes: 1
Views: 977
Reputation: 8497
The NSUserDefaults docs state: "NSUserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value."
Therefore it's no different to setting or getting an object from an in-memory dictionary variable.
However, calling [self.myDefault synchronize];
within a type loop would have a performance consequence, as this opens and writes to the defaults database on disk.
Upvotes: 3
Reputation: 11084
From my understanding, NSUserDefaults isn't the best data store for mass amounts of data. It's recommended to write to plists, or sqlite for larger data sets. User defaults was just for a few user preference settings and isn't built for "storing data" like a typical database is.
You shouldn't really run into performance issues in the loop, though, unless if you're synchronizing for each iteration.
Upvotes: 0