I have an NSOutlineView
bound to an NSTreeController
. My data items are a custom class, let's call them Row
, and suppose a Row
contains a name
and a numeric field called number
.
All these Row
s are found in let's say a RowContainer
which has a rows
mutable array holding the parent (level 0) rows. Each row also has a children
NSMutableArray
member which holds its children.
I have this working, and I want to display under the outline view a text field with the sum of all the number
values of the rows.
I bound this text field to a total
property of the RowContainer
. Now the problem is how or from where to trigger the recalculation of the total
property, since this involves a recursive walk on the tree of rows, and I always get a Collection was mutated while being enumerated
error.
I've tried making a method recalculateTotal
, and calling it from the setNumber
method of the Row
class , but same error occurs. If I put the recalculation logic in the total
getter, I can't trigger it to do the math.
I'm sure the solution is simple but I can't see it.