Reputation: 41
Please give me suggestion, How can I solve solve this problem..
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Weight" ascending:NO selector:@selector(localizedStandardCompare:)];
NSArray *sortedArray = [arrayToSort sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
I am getting output :
-[__NSCFNumber length]: unrecognized selector sent to instance 0x6a81cf0
2012-05-16 09:54:21.480 MedzioSearch[2188:f803] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInvalidArgumentException> -[__NSCFNumber length]: unrecognized selector sent to instance 0x6a81cf0
Upvotes: 0
Views: 1000
Reputation: 90571
What kind of objects are in arrayToSort
? What is the type of their "Weight" property?
At a guess, some of the objects have a Weight property which is an NSString
while some have a Weight property which is an NSNumber
. As a consequence, the sort is trying to do something like [someString localizedStandardCompare:someNumber]
. Internal to -[NSString localizedStandardCompare:]
, it's invoking -length
on the argument which is an NSNumber
and doesn't recognize that selector.
By the way, property names should begin with a lowercase letter unless they begin with an acronym or initialism (like "URL" or "TIFF"). So, your property should be named "weight", not "Weight".
Upvotes: 2