Set containedItem in setContainer method?


#1

When implementing both setter methods, in setContainedItem, we are setting the container of item to self like this:

[code]- (void)setContainedItem:(BNRItem *)item {
_containedItem = item;

item.container = self;

}[/code]

Why aren’t we doing the same thing in setContainer similar to this:

[code]- (void)setContainer:(BNRItem *)item {
_container = item;

item.containedItem = self;

}[/code]

This seams so simple but I don’t understand why it’s not working


#2

It does not work since the code leads to infinite loop; backpack calls ‘setContainedItem’ with calc and inside of it item.container calls setContainer of calc, inside of it item.containedItem calls setContainer of backpack,and so on.