My application crashes while using NSSortDescriptor
on a NSMutableSet
.
Here is the code
NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:EIKNewsHeadlineAttributeHeadlineId ascending:YES]];
NSArray *orderedHeadlines = [weakSelf.storedHeadlines sortedArrayUsingDescriptors:sortDescriptors];
Here storedHeadlines is the NSMutableSet
and my sort descriptor key is EIKNewsHeadlineAttributeHeadlineId
which is a NSString @"headlineId”
.
My mutable set contains objects of a certain class type and that class has a property called headlineId
on which I am trying to sort the mutable set.
I am performing this sorting inside a performBlock
on a private Queue. I checked my weakSelf
and the NSMutableSet
. Both are non nil.
What is causing the issue?
From the crash log it looks like some of the elements in your array are not NSString
. The line that says this is objc_msgSend() selector name: length
This means the objects in the array do not respond to the length
selector.
I believe the problem is in the JSON to mutable set parsing. If you would print the contents of the set, right before you sort it, it might give you an idea what objects in the array are the wrong ones.
Could you post the code that parses the JSON?
If it is not possible, you could filter the set before sorting, eliminating all elements that are not of type NSString
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.