I’m using a NSSortDescriptor to sort my tableView but this line is making trouble:
if (buttonIndex == 0) {
sortDesc = [[NSSortDescriptor alloc] initWithKey:@"Rate" ascending:NO];
}
“Rate” is a Number string in a plist (array with dictionaries).
If dictionary is unrated, default value is “0” and if it is rated, value is “1”, “2”, “3”, “4”, “5” or “6”. Why can’t I sort by these values, and how to do so?
‘NSInvalidArgumentException’, reason: ‘-[__NSCFNumber length]:
unrecognized selector sent to instance 0x6c382c0’
EDIT:
The problem is that I am rating the dictionary with a string instead of Number:
[mutDict setValue:@"0" forKey:@"Rate"];
How to set a number for Rate instead of string?
You can use
NSNumberinstead of a string literal:Other class methods for
NSNumberincludenumberWithLong,numberWithDouble, andNumberWithFloat.