3
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES];

sortedFloats = [Arr_distance sortedArrayUsingDescriptors:
                    [NSMutableArray arrayWithObject:sortDescriptor]];

where sortedFloats is NSMutableArray and Arr_distance is also NSMutableArray

I got the warning Incompatible pointer types assigning to 'NSMutableArray ' from 'NSArray ' still result is correct, but whats the warning about?

0

4 Answers 4

5

Take your sortedFloats as NSArray instead of NSMutableArray. You will find your warning disappeared.

Enjoy Programming

Sign up to request clarification or add additional context in comments.

Comments

2

There is two issues in that code:

  1. Parameter type of sortedArrayUsingDescriptors is NSArray you are passing an NSMutableArray
  2. Return type of sortedArrayUsingDescriptors is NSArray you are assigning it to NSMutableArray object

Check the method signature:

- (NSArray *)sortedArrayUsingDescriptors:(NSArray *)sortDescriptors

Comments

0

In sortedArrayUsingDescriptors: you default object you should pass is NSArray.You are getting the warning as you are passing NSMutableArray.

According to the documentation:

- (NSArray *)sortedArrayUsingDescriptors:(NSArray *)sortDescriptors

Comments

0

Here sortedFloats is object of NSMutableArray and also you sort the array using array key with sortedArrayUsingDescriptors method of NSMutableArray which return NSArray..

so here this sortedArrayUsingDescriptors method's returns type is NSArray and you store this return type array in object of NSMutableArray name is sortedFloats so take sortedFloats as a object of NSArray class. i hope this help you...

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.