I'm getting an error I can't shake. When I try to access an id <NSObject, NSCoding>
's property with valueForKey
the code is fine for the function parameter, item
, but is not for a similar id
I retrieve out of an array. Why is this?
- (void) insertItem:(id<NSCoding, NSObject >) item {
for (int i = 0; i < [self.sortDescriptors count]; i++) {
NSString *propertyString = self.sortDescriptors[i].key;
int idx = 0;
id<NSCoding, NSObject > comparisonItem = self.items[idx];
while ([[item valueForKey: propertyString] compare:[comparisonItem valueForKey: propertyString]] == NSOrderedAscending) {
....
It's this call:
[comparisonItem valueForKey: propertyString]
That is producing this error:
No known instance method for selector 'valueForKey:'
What am I missing and how can I do the comparison for a dynamically named property?
Instead of id<NSCoding, NSObject >
, type this value as an NSObject*
.