Performance Optimization: Why We Can't Use valueForKeyPath:

Recently I was coding away and found myself needing to access something three levels down in a dictionary. I immediately cringed at the thought of the following:

[[[info objectForKey:@"tile-data"] objectForKey:@"file-data"] objectForKey:@"_CFURLStringType"];

Why? Because it’s ugly. I mean, the code to get an object out of a dictionary completely buries which object I’m getting. It would be much nicer just to do this:

[info valueForKeyPath:@"tile-data.file-data._CFURLStringType"]

But I was wary enough to run some speed tests, using the harness written by Mike Ash for his performance tests.…