Hey All,
so I'm working on a little app, and for right now, to get the interface working correctly, I am adding some static objects to an NSMutableArray, but when that finishes, it adds the right number of objects, but they are all the same as the last object added.
Item is a custom object with this init method:
Then, in a method in my AppDelegate, I build some tempItems:
If I have calls to NSLog before adding objects, it shows that tempObject is what I want it to be. When that is all done, I can see that list has 4 objects in it, but they are all the same as the last object added.
I feel like this is probably very easy to fix, but searching on Google, I couldn't find anything that worked. I tried releasing, and autoreleasing the tempObject after adding to the list and before changing it to the new object without success.
Any suggestions?
Dan
so I'm working on a little app, and for right now, to get the interface working correctly, I am adding some static objects to an NSMutableArray, but when that finishes, it adds the right number of objects, but they are all the same as the last object added.
Item is a custom object with this init method:
Code:
- (Item *)init {
self = [super init];
if (self) {
category = @"";
storeName = @"";
storeAddress = @"";
storeHours = @"";
name = @"";
quantity = 0;
price = 0.0;
description = @"";
picture = @"";
upc = 0;
}
return self;
}
Then, in a method in my AppDelegate, I build some tempItems:
Code:
Item *tempItem = [[Item alloc] init];
// make a new item
tempItem.category = @"Groceries";
// all the other properties are set
[list addObject:tempItem];
// same code for adding 3 more objects
If I have calls to NSLog before adding objects, it shows that tempObject is what I want it to be. When that is all done, I can see that list has 4 objects in it, but they are all the same as the last object added.
I feel like this is probably very easy to fix, but searching on Google, I couldn't find anything that worked. I tried releasing, and autoreleasing the tempObject after adding to the list and before changing it to the new object without success.
Any suggestions?
Dan