The Old Blog Archive, 2005-2009

One Thing that Will Definitely Break

Lately I found you can actually call valueForKeyPath: to retrieve a key from deep dictionary-array combos, such as [aDict valueForKeyPath:@"a.b.c"] instead of [[[aDict objectForKey:@"a"] objectForKey:@”b”] objectForKey:@”c”].

Apple calls it “Key Path” (à la XPath?) and it plays an important role in Key-Value Coding/Observation. The biggest problem, however, is that it uses the symbol “@” to perform some functions on array data (e.g. you can do average or count or total, those db/spreadsheet thing, using @ modifier in a key path).

That is in direct conflict with ObjectiveFlickr’s current XML-to-NSDictionary convention, which follows BadgerFish’s XML-to-JSON convention, ie. using @ symbol to mark that it’s an attribute of an XML tag.

Either I’ll have to move attributes to another key, e.g. aTag._attr, or have to use another symbol that is not “@”.

In any case, I’m going to break that part of ObjectiveFlickr. I don’t want to write three left brackets just to retrieve a key, it’s too ugly. KeyPath is a better way, but unfortunately the symbol “@” doesn’t fit into the picture. Only had I knew it before I designed!

Comments are closed.