This is vaguely related to my previous thread but I decided it warranted a thread of its own.
As a newbie Cocoa programmer I was quite pleased with myself when I figured out how to use bindings to count the entity instances on the other end of a to-many relationship (using an array controller) and even to sum a property of the instances:
However, I would also like to count the number of items that match a certain criteria (which I believe calls for a predicate).
For example, I'd like to do something like the following (which obviously doesn't work):
For now I would like to do it in interface builder for my own learning and so I can later compare this method vs some smarter code/calculated transient values.
I assume I need to:
1) Create a new array controller (as applying a predicate to one of the existing ones will mess up what's already working, correct?)
2) Set the fetch predicate to something like
3) Bind to arrangedObjects with a Model Key Path of
Am I on the right track here?
Also, I already have two array controllers with exactly the same name (but different object IDs). Using this predicate thing will potentially add a third with that name. Is that normal and acceptable?
Thanks in advance!
Matt
P.S. I realise that bindings aren't the be-all and end-all and after reading this thread I realise bindings/KVC aren't necessarily optimal performance-wise. I'm just after a proof-of-concept at the moment and also to learn more about how the technologies interact!
As a newbie Cocoa programmer I was quite pleased with myself when I figured out how to use bindings to count the entity instances on the other end of a to-many relationship (using an array controller) and even to sum a property of the instances:
Code:
relationshipName.@count
relationshipName.@sum.otherEntityProperty
However, I would also like to count the number of items that match a certain criteria (which I believe calls for a predicate).
For example, I'd like to do something like the following (which obviously doesn't work):
Code:
relationshipName.@count(subRelationshipName.@sum.subRelProperty == SELF.entityProperty)
-- OR --
transactions.@count(transactions.allocations.@sum == SELF.amount)
For now I would like to do it in interface builder for my own learning and so I can later compare this method vs some smarter code/calculated transient values.
I assume I need to:
1) Create a new array controller (as applying a predicate to one of the existing ones will mess up what's already working, correct?)
2) Set the fetch predicate to something like
Code:
relationshipName.subRelationshipName.@sum.subRelProperty == SELF.entityProperty
-- OR --
transactions.allocations.@sum.amount == SELF.amount
Code:
relationshipName.@count ( -- OR -- transactions.@count)
Am I on the right track here?
Also, I already have two array controllers with exactly the same name (but different object IDs). Using this predicate thing will potentially add a third with that name. Is that normal and acceptable?
Thanks in advance!
Matt
P.S. I realise that bindings aren't the be-all and end-all and after reading this thread I realise bindings/KVC aren't necessarily optimal performance-wise. I'm just after a proof-of-concept at the moment and also to learn more about how the technologies interact!