我想在的NSMutableArrayobjective-c:如何更新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;
}
}
我想知道,如果有什么更好的办法做到这一点,以更新的对象?
是 - “但为什么”? – 2011-08-30 06:56:21
因为[NSArray objectAtIndex:index]返回指向对象的指针。 – Nekto
使用objectAtIndex检索值,修改它,然后使用replaceObjectAtIndex更好。 – afollestad