tags:

views:

169

answers:

1

I am not sure if this can be done -- it looks like it should be a straightforward thing but I keep getting "the entity Sale is not key value coding-compliant for the key "@sum"."

I using "@[email protected]" for the Table column value binding. I am doing it right, or what is the right way to do this?

Screenshot

+4  A: 

First, take an other look at the KVC Programming Guide's Set and Array Operators section. KVC's set and array operators are powerful, but it's easy to get them wrong, even after you've grokked the system. And it's nearly impossible to get them right until you do.

That said, I think you mean you used "@[email protected]" since you say the error involves @sum, and @sale isn't a legal KVC operator. Assuming that's right, and that you have a model like foo->departments->sales.amount, you probably want something like

"@[email protected]"

to get the total sales for all departments.

Barry Wark
Moreover, the questioner should definitely use `@distinctUnionOfSets`, not `@unionOfSets`, in order to not count any departments' sales twice.
Peter Hosey
I still get this "the entity Company is not key value coding-compliant for the key "@sum" " and I tried: - @[email protected] - @[email protected] - [email protected] far all these doesn't work if I specified it in the IB's Binding Model Key Path value field.However if I create another method to return "[email protected]" from the entity class and have the IB Binding value to refer to it as "amount" it works. This means that "[email protected]" works if I put it in code and have the IB Model Key Path call from the method. I'm lost.
Seymour Cakes
@Seymore Yup, I was right: even when you think you know KVC, it's easy to get wrong. I usually have to play around in PyObjC or at the debugger console to get it right. Without a clearer picture of your object model, it's hard for me to figure out exactly what's going on. Could you post a screen shot of the object model and/or some code?
Barry Wark
Seymour Cakes
@Seymore, We need to see the object model that you're applying the key path *to*. The Core Data managed object model (if you're using Core Data) or the Xcode->Design->Class Model->Quick Model of the classes or some code...
Barry Wark
Seymour Cakes: That error message means you're trying to use the `@sum` keyword with a single object, not a collection. Probably, the Company whose departments you've tried to sum. Without the knowledge of what your model looks like, I'd guess that your first key path is right, but you had a Sale object as the value of your `departments` property. This may be an under-retention (you over-released your `departments` collection, and a Sale object got allocated in its place). Check your memory management.
Peter Hosey