1
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 Answers 2

6

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)]]
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.