P.167 - Entertaining bug


#1

The authors say [quote](For an entertaining bug, have both accessors automatically call the other. this creates an infinite loop: addAsset: calls setHolder: which calls addAsset: which calls setHolder: which…)[/quote]

Can someone confirm exactly what coding changes need to be implemented to cause this entertaining bug…?

Many thanks,

Luke


#2

Have them call each other so something like this

[code]-(void)addAsset(BNRStockHolding *)s {
//your code here

[self removeAsset:s];
}

-(void)removeAsset(BNRStockHolding *)s {
//your code here

[self addAsset:s]
}[/code]

This will continue to loop through since they go back and forth.