Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update an object in NSMutableArray?

I am trying to update an object in NSMutableArray.

Product *message = (Product*)[notification object];
Product *prod = nil;

for(int i = 0; i < ProductList.count; i++)
{
    prod = [ProductList objectAtIndex:i];
    if([message.ProductNumber isEqualToString:prod.ProductNumber])
    {
        prod.Status = @"NotAvaiable";
        prod.Quantity = 0;
        [ProductList removeObjectAtIndex:i];
        [ProductList insertObject:prod atIndex:i];
        break;
    }
}

Is there any better way to do this?

like image 687
Azhar Avatar asked Aug 30 '11 06:08

Azhar


1 Answers

Remove lines:

[ProductList removeObjectAtIndex:i];
[ProductList insertObject:prod atIndex:i];

and that will be ok!

like image 90
Nekto Avatar answered Oct 07 '22 22:10

Nekto