Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting -[__NSArrayI addObjectsFromArray:]: unrecognized selector sent to instance 0xa0c5f70 error

I am geting error while I am adding objects in my array -[__NSArrayI addObjectsFromArray:]: unrecognized selector sent to instance 0xa0c5f70

id max;
   NSMutableArray * MovePointsArray=[[NSMutableArray alloc]init];
    max=[pointsArray objectAtIndex:0];
    for(int i=0;i<[pointsArray count];i++){

        if ([pointsArray objectAtIndex:i] > max) {
            max=[pointsArray objectAtIndex:i];
            [MovePointsArray addObject:max];
        }

    }

   NSMutableArray * pointArray =[NSArray arrayWithObjects: [pointsArray objectAtIndex:0],[pointsArray lastObject], nil];
    [pointArray addObjectsFromArray:MovePointsArray];

Not getting wehre I am doing mistake.

like image 763
Nishi Avatar asked Jun 12 '26 01:06

Nishi


2 Answers

In last line

NSMutableArray * pointArray =[NSArray arrayWithObjects: [pointsArray objectAtIndex:0],[pointsArray lastObject], nil];

replace NSArray with NSMutableArray

Thanks,

like image 182
Akshay Aher Avatar answered Jun 14 '26 15:06

Akshay Aher


Correct code

NSMutableArray * pointArray =[[NSMutableArray alloc] initWithObjects: [pointsArray objectAtIndex:0],[pointsArray lastObject], nil];
[pointArray addObjectsFromArray:MovePointsArray];

You were initializing pointArray with NSArray, and NSArray doesn't have the method in your next line addObjectsFromArray which is a NSMutableArray method..

like image 26
iphonic Avatar answered Jun 14 '26 16:06

iphonic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!