How do I update an object in NSMutableArray?
For updating, use
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject
But it is not needed in this case, since you are modifying the same object.
Remove lines:
[ProductList removeObjectAtIndex:i];
[ProductList insertObject:prod atIndex:i];
and that will be ok!
You could start by using fast enumeration, which is faster and easier to read. Also, you don't need to remove and insert the object, you can just edit it in line. Like this:
Product *message = (Product*)[notification object];
for(Product *prod in ProductList)
{
if([message.ProductNumber isEqualToString:prod.ProductNumber])
{
prod.Status = @"NotAvailable";
prod.Quantity = 0;
break;
}
}
(Is ProductList
an object? If it is, it should start with a lowercase letter: productList
. Capitalized names are for classes. Also, Status
and Quantity
are properties and should too start with a lowercase letter. I highly suggest you follow the Cocoa naming conventions.)