J0k3R
J0k3R

Reputation: 303

Change Values on my plist iOS

I have a .plist with one array and in this array i have some NSDictionary in it. Now I want to change in my Dictionary some Values. My Idea is to load the whole array, find the value, change it, and write over the whole array. but it cost a lot of time. Do you know a better way to change special values.

Upvotes: 0

Views: 165

Answers (3)

Stavash
Stavash

Reputation: 14304

There's no time issue here. Let's talk big-O notation:

  1. Worst case cost of fetching an NSDictionary from the array: O(log(n)) - source
  2. Worst case cost of fetching a value from within the dictionary: O(log(n)) (see above source)
  3. Cost of performing any constant amount of operations on that value within the dictionary O(c)

O(log(n))+O(log(n))+O(c)=O(log(n))

So you are 'stuck' with O(log(n)) which isn't bad at all.

Upvotes: 2

Snips
Snips

Reputation: 6753

If you're going to persist data using a .plist, there's no alternative than to write out the whole file if you make a change.

An alternative for storing large amounts of data that would allow you to update individual records would be to use CoreData - which is effectively a database stored on the device.

Core Data is a lot more complicated than using a plist, but more scalable, and all the other benefits that come with using a database.

Upvotes: 1

Minthos
Minthos

Reputation: 900

How big is the plist? How often do you do it? It shouldn't be a performance problem..

Upvotes: -1

Related Questions