I am trying to do a program where there is a product
which I wish to be moved into a storehouse
.
Example:
Move 25 crates of Apples from Inventory (on hand) to a Storehouse.
When I add the product to the storehouse's listOfProducts
and then zero the stock, for some reason the storehouse's product is also affected, even though it shouldn't be.
The process should be;
- Find the product object you want to move into the storehouse
- Update the storehouse qty, making sure the qty is adding the stock you have on hand
- Add a product object to the storehouse's listOfProducts
- Make the inventory stock zero (0)
But its making the storehouse qty 0 too? Why? There appears to be no reason why it should be doing this.
It appears to have forced a symlink between the objects I am referencing, even though this is not what is meant to be happening.
Do I need to be making a copy of the object first?
Some notes.
a. Storehouse is an object, each city has a storehouse (ie. city.listOfStorehouses).
b. city.listOfStorehouses is kept in a singleton so saving the state or passing it from page to page is not a problem.
c. The item gets added to the storehouse, but the qty resets to zero? But why?
// Try to move X goods from inventory -> storehouse
NSLog(@"Goods to move = %@, %d crates", self.product.name, self.crates);
// I add the qty to the product I want to put into the storehouse
self.product.qty += self.crates;
// Append the array (I should check if the product already exists but this does not matter right now)
[self.storehouse.listOfProducts addObject:self.product];
// Reset crates because it should always be zero because you've moved them
// from your inventory into a storehouse
self.crates = 0;
Okay, so when on the stock page and I move 25 Apples from inventory to the storehouse the reference and qty seem fine.
However, if I refresh/reload the page the qty is reset to zero in the storehouse, even though there is an item there.
I do not know what is causing the storehouse item qty to be set to zero.
Here is a log output;
// Log output
// Stock page
// Goods to move = Apples, 25 crates, seems to be storing fine, no problem.
2013-02-16 09:40:27.257 TestApp[1524:c07] Storehouse = (25/500)
2013-02-16 09:40:27.260 TestApp[1524:c07] #0 storehouse item = Apples with 25 crates
// Previous page
// When I go back to the previous page, the qty is zero?? WHY?
2013-02-16 09:41:33.980 TestApp[1524:c07] Storehouse = (0/500)
2013-02-16 09:41:33.980 TestApp[1524:c07] #0 storehouse item = Apple with 0 crates