Objective-C Incompatible pointer types assigning to NSMutableArray from NSArray

1.3k views Asked by At

I have this code

      [[self.client dataClient] getEntities:@"book" query:nil
                    completionHandler:^(ApigeeClientResponse *result)                          {
                        if (result.transactionState ==kApigeeClientResponseSuccess) {
                            _objects = result.response[@"entities"];
                        } else {
                            _objects = @[]; //"Incompatible pointer types assigning to NSMutableArray from NSArray"
                        }
                        [self.tableView reloadData];
                    }];

It shows me error "Incompatible pointer types assigning to NSMutableArray from NSArray"

2

There are 2 answers

0
shallowThought On

You are trying to assing a NSArray (@[]) to a variable of type NSMutableArray.

Replace:

 _objects = @[];

with:

_objects = @[].mutableCopy;

Even you do not mention an error in the first if clause, you have to replace this also.

_objects = [NSMutableArray arrayWithArray:result.response[@"entities"]];
0
TheHungryCub On

_objects is implemented in NSArray and returns an NSArray even when called on an NSMutableArray.

assign [NSMutableArray array];