我正在排序一个可变数组。对于排序我使用:
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"pubDate" ascending:NO];
[recent sortUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
recent1 = [recent sortedArrayUsingDescriptors:descriptor];
[descriptor release];
我收到此错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object'
该行
recent1 = [recent sortedArrayUsingDescriptors:descriptor];
显示警告
在我的代码中,recent
和recent1
都是NSMutable
数组。我哪里出错?
答案 0 :(得分:1)
recent1 = [recent sortedArrayUsingDescriptors:descriptor];
必须是:
recent1 = [recent sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
虽然我不知道你为什么要对你已经在上面直线上用相同排序描述符排序的数组进行排序。