1
votes
NSMutableArray *sortedReleases = [theReleases sortedArrayUsingComparator:^(id a, id b)

I get the following:

Incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'

I have to have sortedReleases as a NSMutableArray. How do I get past it?

Thanks

2

2 Answers

6
votes

This should do the trick I think (written in browser) — NSMutableArray inherits from NSArray, so you can use the arrayWithArray constructor.

NSMutableArray *sortedReleases = [NSMutableArray arrayWithArray:[theReleases sortedArrayUsingComparator:^(id a, id b)]]
1
votes

sortedArrayUsingComparator returns a NSArray*, you want a NSMutableArray*. In ObjC the mutable types inherit from the immutable types, so you can't just use the NSArray*. You need something to take your NSArray* and give you the equivolent NSMutableArray*. In this case the NSMutableArray arrayWithArray method will do it.

Try something like:

NSMutableArray *immutableSortedReleases = [theReleases sortedArrayUsingComparator:^(id a, id b)...]
NSMutableArray *sortedReleases = [NSMutableArray arrayWithArray:immutableSortedReleases];

Or if sufficiently clear, skip having immutableSortedReleases, and put the arrayWithArray call inline.