我有一个正在复制到 NSMutableArray 的类的对象。我这样做了5次。但是,每当我尝试从该数组中检索对象时,它们都是相同的。
这是示例代码:
[myProperty setAddress:@"Av. dos Estados, 70."];
[myProperty setPropType:casaRua];
[myProperty setRentalPrice:1430.0];
[propertiesArray addObject:myProperty];
myProperty = [propertiesArray objectAtIndex:0];
NSLog(@"Price 0 %.2f\n", [myProperty rentalPrice]); //In this I got 1430.0
[myProperty setAddress:@"Av. das Nações, 10. Ap: 103."];
[myProperty setPropType:apto];
[myProperty setRentalPrice:450.0];
[propertiesArray addObject:myProperty];
myProperty = [propertiesArray objectAtIndex:0];//indexPath.row];
NSLog(@"Price 0 %.2f\n", [myProperty rentalPrice]); **//In this I got 450.0???**
myP = [propertiesArray objectAtIndex:1];//indexPath.row];
NSLog(@"Price 1 %.2f\n", [myP rentalPrice]); //In this I got 450.0
我究竟做错了什么?似乎该数组已被 addObject 覆盖