IPhone: warning pops up when reverse NSMutablearray
I need a reverse (sorting descending) NSMutablearray. I tried the following code and it works but got a warning. How can I remove the warning?
NSMutablearray *resStatusArray;
[resStatusArray sortUsingSelector:@selector(compare:)];
resStatusArray=[[resStatusArray reverseObjectEnumerator] allObjects];
Warning:Incompitable pointer types assigning to 'NSMutablearray*_strong' from ' NSarray *'
+3
source to share
4 answers
Set it equal:
[NSMutableArray arrayWithArray:[[arrayNameToReverse reverseObjectEnumerator] allObjects]];
This essentially creates a new array from the old modified array, but vice versa. The reason it works is because NSMutableArray is a subclass of NSArray. So your code to modify your array will look like this:
resStatusArray = [NSMutableArray arrayWithArray:[[resStatusArray reverseObjectEnumerator] allObjects]];
0
source to share