Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone:Got warning when reverse a NSMutablearray

I need reverse(sort in descending order) a NSMutablearray.I tried the following code and it works,but got a warning. How could I remove the warning?

NSMutablearray *resStatusArray;

[resStatusArray sortUsingSelector:@selector(compare:)];

    resStatusArray=[[resStatusArray reverseObjectEnumerator] allObjects];
Warning:Incompitable pointer types assigning to 'NSMutablearray*_strong' from ' NSarray *'
like image 249
nithin Avatar asked Jan 28 '26 18:01

nithin


2 Answers

user1118321 is correct in the explanation. To fix it, you would create a new mutable array. I suspect this is safer than a cast.

resStatusArray = [NSMutableArray arrayWithArray:[[resStatusArray reverseObjectEnumerator] allObjects]];
like image 103
Jaanus Avatar answered Jan 30 '26 12:01

Jaanus


The allObjects method returns an NSArray*, not an NSMutableArray*, so the compiler is telling you that your assignment to an NSMutableArray* variable is incorrect.

like image 45
user1118321 Avatar answered Jan 30 '26 11:01

user1118321



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!