Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an NSMutableArray with custom objects.

I can addObjects, removeAllObjects and other operations with the array.

However, as soon as I sort the array via sortedArrayUsingDescriptors i cannot perform any operations anymore such as removeallobjects. When debugging the code simply stops at this point.

Does anyone have an explanation ?

share|improve this question
    
Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. –  Hot Licks Jan 7 at 0:18
    
what bs answer is that? –  Mozzak Jan 7 at 0:20
2  
It's not a BS answer, it's a closing code. –  Hot Licks Jan 7 at 0:21

1 Answer 1

up vote 1 down vote accepted

sortedArrayUsingDescriptors: returns a NSArray, not NSMutableArray.

you should use sortUsingDescriptors: to sort in place.

NSArray *sortedArray = [array sortedArrayUsingDescriptors:...];

vs.

[mutableArray sortUsingDescriptors:...];
share|improve this answer
    
ahhh this makes total sense. Awesome answer. –  Mozzak Jan 7 at 0:20
    
I will but I have to wait a few more minutes it tells me. –  Mozzak Jan 7 at 0:27
    
I will @Zero. Thanks to everyone helping me out here. –  Mozzak Jan 7 at 0:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.