NSDictionaries, plists and interface elements

Hello there,

NSdictionaries lend themselves perfectly to manage a little data base.

You get the plist file for the model, the NSDictionary and a few coding for the controller, and the view part in IB. A great MVC application, all included in Xcode: an editor for the plist, a compiler/linker for your code and IB for your interface. Sounds good.

But of course, despite of an abundant documentation and innumerable examples (mainly in Objective-C), I stay on the edge of this deep forest, not daring to venture there without understanding the way forward…

For instance: what is the goal of a DictionaryController? Is it just here to make an impression or does it really do things undoable via a dictionary with property bindings?

What if you make a arborescent structure into your dic, for example “animal / vertebrate / mammal /…”. How do you point to a specific animal? Sort of “animal’s vertebrate’s mammal’s xxx” key? If you fetch the key “vertebrate” do you end up with an array of keys contained in it? Does a key have to be unique, or only inside a “super key”?

Is there somebody around here comfortable with these notions, and could try to explain them to me? I ask this, before more precise questions.

Thank you in advance!

It’s hard to answer this without a few more specifics. As far as a dictionary controller, I think the main use for that is if you want to use a dictionary (rather than an array or array of dictionaries) as the data for a table. I son’t quite understand your “arborescent structure” question. What would the value of your vertebrate key be? An array of vertebrates? I’ve used dictionaries pretty extensively, and I’m sure I could answer your questions if they are more specific.


Hi Ric,

Ok I’ll be more specific, using not an example but my concrete app.

I have to make a data base containing all the verbs of the program of my school, all over the years. Then find any verbal form into this data base, giving some keys.

Consider one verb (they are french verbs but of course it’s not particular to this language): We have a “main key”, the infinitive of the verb, let’s say “avoir” (to have). Every verb has conjugation modes, “indicative”, “conditional”, “subjunctive”… For every mode we have tenses “present”, “past present” and so on. For each tense we have a personal forms, “je”, “tu”, “il”… and finally we get the verbal form.

For example, if I give the keys (in order): “avoir”, “conditional”, “present”, “il” I should get “aurait”, the correct verbal form.

I already begun to fill a plist file into my project. It’s quite simple (but annoying) to do. I can already create an NSDictionary (non-mutable of course) and fill it with the file’s contents.

Now I’m stuck. Given the structure above, how can I retrieve a given verbal form?

You use valueForKeyPath. For your example, it would look like this, if the name of the dictionary was dict and “avoir” was a key at the top level:

log dict’s valueForKeyPath_(“avoir.conditional.present.il”)


.that simple?

So, as the keys are names, we can specify them using a NSString, built programmatically, like:

set myKey to “verbes.” & “.” & verbName & “.” & modeName & “.” & tenseName & “.” & personName
set myForm to gVerbDictionary’s valueForKeyPath_(myKey) – ?

Yes, the keys are just strings, so you can build them like that.


Thank you very much, Ric, have a good week end, I’ll keep you informed (and other users too).


Ok, next step.

The verbs are grouped by degree, ranging from 5 to 11. Each degree has a given number of verbs. I’d like to allow the verbs to be selected individually, or by degree, like this:
✓ 5
✓ verb a
✓ verb b
✓ verb c

  • 6
    ✓ verb a
    verb b
    ✓ verb c

where ✓ means a checked box, nothing means unselected and - means (for a degree) partly selected. If a degree is selected or unselected, all the verbs of this degree are selected or unselected. This seems to be the simplest et most intuitive way of doing it for an end user.

The data are already organized into a .plist file. I could load it into a NSDictionary, but the interface part is not so obvious.

There is a class named NSOutlineView which could be what I’m looking for, but as usual, examples are not so clear, and I’ve read some alarming news on bugs or curious behavior for this class. Much more, it seems that you can’t have text and check box together without subclassing NSButtonCell (a thing I can’t do). Or you use two columns and then you get a visually unpleasant alignment.

Could somebody help me to solve this (these) problem (s)?

Thank you!

I think you could do this with a view-based (as opposed to cell-based) NSOutlineView. You can make a view that includes a label and a check box without any subclassing (it can be designed in IB). I can’t tell from this post, how this view you want to create relates to the dictionary from your last post. Once you select the verbs or degree, what will you do with that list of selected items?


Well, my app will be essentially a “teaching assistant”, proposing randomly generated verbal forms (the user has to guess the solution given the verb, the tense and the person, then the program will compare with the correct one).

In order to generate verbal forms corresponding to certain degree, the user has to select a set of verbs from the main list (74 verbs in 7 degrees). Let’s say, only the verbs of degrees 5 and 6.

I had the idea to make two .plist files: the first one, containing only the infinitives of the verbs, would allow to select them, and then I would have used these selected keys to retrieve the whole conjugated verb contained into the second .plist file.

This structure seemed to be easier to update, if, for example, verbs are moved in the future from one degree to another.

I noticed this option cell-based / view-based but did not investigate more. Obviously, I should have to?

In fact, I found an example (only a picture) of what the result should be, at:

Well, well, well. dictionaries, subsets, excluded keys. something looks fuzzy in my project model structure. Back to the drawing board.