I am trying use NSSortDescriptor and sorts "Units" which have a set of "Devices". Each device has a signal strength. I would like to sort units by the device with the highest signal strength. I just found a page about collection operators and I think I'm close but I still can't quite get it to work.
NSSortDescriptor *rssiSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"[email protected]" ascending:[self sortByRSSIAscending]];
I'm guessing the issue here is that devices can't be directly compared to each other, so the @max operator doesn't work. Is there a way to override this to compare by signal strength?
I have added this to my device model:
- (NSComparisonResult)compare:(PersistedNokeDevice*)other
{
if (self.signalStrength < other.signalStrength) {
return NSOrderedAscending;
}
if (self.signalStrength == other.signalStrength) {
return NSOrderedSame;
}
return NSOrderedDescending;
}
I am getting this error Keypath containing KVC aggregate where there shouldn't be one; failed to handle [email protected]
Is there a way to make this work or do I need to rethink my strategy?