How to detect if using Key or KeyPath

36 views Asked by At

I just ran into the problem where I was trying

[object valueForKey:key]

when I should have used

[object valueForKeyPath:key]

As a quick fix I did this.

if ([[sortDescriptor key] rangeOfString:@"."].location != NSNotFound ) {
     sectionHeader = [object valueForKeyPath:[sortDescriptor key]];
} else {
     sectionHeader = [object valueForKey:[sortDescriptor key]];
}

Is this the best way to handle this scenario?

0

There are 0 answers