Saving records

So in the app I’m working on, I want to move from a hardcoded list of records to a model where I can add records to the list as needed. currently, the record looks like this:

{serverName:“Some name”,serverURL:“",serverAPIKey:"somestring”}

so it SEEMS to me, based on poking around, that the way to store this is as an NSMutableArray of NSDictionaries? Since I’d want to be able to add and remove dictionaries, NSMutableArray seems to be the better option.

Looking at the docs for NSUserDefaults, this seems to make sense given arrayForKey:

The thing I’m not seeing is what’s the key for the array? How do I set that when I store it, so I have a key with which to retrieve it?

Oh, also, I don’t see a good way to set defaults based on either arrays or dicts

When you store it, mutability is irrelevant. When you retrieve it it will be immutable, but you can make a mutable copy using mutableCopy().

It’s whatever you want it to be – it’s just a label of sorts, so make it something relevant.

Use setObject:.

so basically, if I use arrayForKey, it’s going to grab the first thing in there and assign it to the key I tell it to?

which is what I want so if that’s how it works, that’s cool.

No, it’s going to grab the thing that was assigned with that key. You use a key to store a value – using setObject:forKey: (or a binding to shared defaults using the key) – and you use the same key to retrieve it – via arrayForKey: or objectForKey:.

okay, got it. Makes sense, and thanks again!