views:

298

answers:

1

I am new to iphone development.I am sorting an mutable array. For sorting

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"pubDate" ascending:NO]; 
[recent sortUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];  
recent1 = [recent sortedArrayUsingDescriptors:descriptor];
[descriptor release];

I am getting this error

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object'

The line

recent1 = [recent sortedArrayUsingDescriptors:descriptor];

show warnings

  • "passing argument 1 of 'sortedarrayusingdescritors' from distinct objective c type " and
  • "assignment from distinct objective c type"

I my code both recent and recent1 are NSMutable array.Wher do i go wrong?please help me out.Thanks.

+1  A: 
recent1 = [recent sortedArrayUsingDescriptors:descriptor];

must be:

recent1 = [recent sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];

Though I have no idea why you would want to sort an array that you already sorted with the same sort descriptors on the line directly above.

Ole Begemann