1
votes

With the code below I am getting the error, "Incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray *'." I am not using an NSArray, why am I getting this error and how can I fix it?

(NSMutableArray) = [NSMutableDictionary keysSortedByValueUsingComparator: ^(id obj1, id obj2) {

    if ([obj1 integerValue] > [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedDescending;
    }

    if ([obj1 integerValue] < [obj2 integerValue]) {
        return (NSComparisonResult)NSOrderedAscending;
    }
    return (NSComparisonResult)NSOrderedSame;
}];
1

1 Answers

1
votes

It's because the method keysSortedByValueUsingComparator: returns a pointer to a sorted NSArray containing the keys. You are taking that NSArray pointer and trying to assign it to an NSMutableArray. pointer This is an error because NSArray is the superclass of NSMutableArray and does not respond to all of the same selectors/methods.

You need to assign the output of keysSortedByValueUsingComparator: to an NSArray pointer instead of an NSMutableArray pointer.