FROM : Trent Jacobs
DATE : Wed Mar 26 12:00:21 2008
Thanks Christiaan, that helps a lot. I have been basing what I've said
on the tutorial on
http://developer.apple.com/cocoa/coredatatutorial/index.html
In this example he has an array controller bound to a Commit Messages
entity and another array controller bound to a Version Release entity
(where a version release can have many commit messages). In video 9 he
binds the *content set* of his Commit Messages array controller to the
Version Releases array controller, hence 'filtering' the Commit Messages
array controller to only show those commit messages belonging to the
selected version release.
I now see that by binding the content set in the way he did he was
actually binding the relationship and in doing so, like you said, he
wasn't filtering at all.
I'll use filter predicates then. Thanks again - you've saved me loads of
time. I've already wasted about 2 days because of the misunderstanding
from above. Your help is really appreciated.
Trent.
Christiaan Hofman wrote:
> Maybe I completely misunderstand you. But when you unbind the
> contentSet, why should it display anything? The full contents of
> *which* arrangedObjects? The arrangedObjects are *derived* from the
> contentSet, so not contentSet means no arrangedObjects. I really fail
> to see the "filtering" in this story, becaue you haven't said a word
> about filters, even though you keep mentioning filtering. The
> contentSet binding has nothing to do with filtering.
>
> Christiaan
>
> On 26 Mar 2008, at 9:12 AM, Trent Jacobs wrote:
>
>> Thanks Christiaan.
>>
>> Why would I expect the filtering to be removed when I unbind? My
>> understanding is that when an array controller's content is contained
>> in the arrangedObjects, and that this content is further filtered if
>> the array controller's 'Content Set' is bound to another array
>> controller. So I assumed when the binding to the content set is
>> removed the full contents of the arrangedObjects would be shown. Is
>> this incorrect?
>>
>
> Your understanding is wrong. Actually, none of the statements you make
> here is correct. The contentSet has nothing to do with filtering,
> that's done by the filter predicates.
>
>> (as a possible clarification, I'm unbinding the content set, not the
>> arranged objects.)
>
> I think you misunderstand something about bindings in
> NSArrayController, arrangedObjects is not a key you can bind (you can
> only bind *to* that key), those are generated by NSArrayController
> from whatever its content is. The content can be provided by binding
> either contentSet or contentArray (not both, the result is undefined).
>
>>
>>
>> As for filter predicates... I thought doing it the way I described
>> below was the proper way since it would mean less code and more
>> reliance on binding. I guess I was wrong? :)
>>
>> Trent.
>>
>
> Yes (for the last sentence).
>
> Here's how NSArrayController works:
>
> - You provide the full content of the objects handled by
> NSArrayController by binding either contentSet or contentArray.
> - NSArrayController filters these objects according to the
> filterPredicate (either set or provided through binding) and sorts
> them according to the sortDescriptors (either set or provided through
> binding).
> - arrangedObjects is the *result* of this procedure. You can read it
> in code or bind something else to it.
>
> Christiaan
>
>> Christiaan Hofman wrote:
>>>
>>> On 25 Mar 2008, at 9:15 PM, Trent Jacobs wrote:
>>>
>>>> The app I'm writing is centered around a particular list of objects
>>>> (for example a list of items in a shop) with various filters
>>>> allowed. it's a core data app and I'm using bindings wherever
>>>> possible.
>>>>
>>>> In the model I'm using I have an entity for my objects and I've set
>>>> up relationships to the entities I'll be filtering on (for example
>>>> brand, colour, whatever).
>>>>
>>>> I've got everything with perfectly when I hook up the bindings in
>>>> IB, i.e. when I select a brand the list of objects is filtered to
>>>> only show objects of the selected brand. However, when I try to do
>>>> the bindings in code it doesn't work.
>>>>
>>>> To create the bindings I use:
>>>>
>>>> [myObjectController bind : @"contentSet"
>>>> toObject : filterController
>>>> withKeyPath : @"selection.objects"
>>>> options : nil];
>>>>
>>>> where myObjectController and filterController are NSArrayController
>>>> objects and selection.objects represents the relationship in the
>>>> model.
>>>>
>>>> This works fine. However, when I remove the contentset binding I
>>>> would expect the filtering to be removed.
>>>
>>> Why? The -unbind: method does not trigger a reload,
>>> -bind:toObject:withKeyPath:options: however does. This does make
>>> sense to me.
>>>
>>>> This doesn't happen. What happens is that the list of objects stays
>>>> the same although the controlling relationship to the filtering
>>>> array controller is gone, i.e. I change brands and the list stays
>>>> constant. To remove the bindings I am simply using:
>>>>
>>>> [myObjectController unbind : @"contentSet"];
>>>>
>>>> I think this is happening because the NSArrayController is not
>>>> being told to refresh but i can't find how to force a refresh.
>>>>
>>>
>>> -rearrangeObjects could do it. Or binding to some other property.
>>>
>>>> Any ideas?
>>>>
>>>> Thanks!
>>>
>>> Why aren't you just using filter predicates?
>>>
>>> Christiaan
>>>
>
DATE : Wed Mar 26 12:00:21 2008
Thanks Christiaan, that helps a lot. I have been basing what I've said
on the tutorial on
http://developer.apple.com/cocoa/coredatatutorial/index.html
In this example he has an array controller bound to a Commit Messages
entity and another array controller bound to a Version Release entity
(where a version release can have many commit messages). In video 9 he
binds the *content set* of his Commit Messages array controller to the
Version Releases array controller, hence 'filtering' the Commit Messages
array controller to only show those commit messages belonging to the
selected version release.
I now see that by binding the content set in the way he did he was
actually binding the relationship and in doing so, like you said, he
wasn't filtering at all.
I'll use filter predicates then. Thanks again - you've saved me loads of
time. I've already wasted about 2 days because of the misunderstanding
from above. Your help is really appreciated.
Trent.
Christiaan Hofman wrote:
> Maybe I completely misunderstand you. But when you unbind the
> contentSet, why should it display anything? The full contents of
> *which* arrangedObjects? The arrangedObjects are *derived* from the
> contentSet, so not contentSet means no arrangedObjects. I really fail
> to see the "filtering" in this story, becaue you haven't said a word
> about filters, even though you keep mentioning filtering. The
> contentSet binding has nothing to do with filtering.
>
> Christiaan
>
> On 26 Mar 2008, at 9:12 AM, Trent Jacobs wrote:
>
>> Thanks Christiaan.
>>
>> Why would I expect the filtering to be removed when I unbind? My
>> understanding is that when an array controller's content is contained
>> in the arrangedObjects, and that this content is further filtered if
>> the array controller's 'Content Set' is bound to another array
>> controller. So I assumed when the binding to the content set is
>> removed the full contents of the arrangedObjects would be shown. Is
>> this incorrect?
>>
>
> Your understanding is wrong. Actually, none of the statements you make
> here is correct. The contentSet has nothing to do with filtering,
> that's done by the filter predicates.
>
>> (as a possible clarification, I'm unbinding the content set, not the
>> arranged objects.)
>
> I think you misunderstand something about bindings in
> NSArrayController, arrangedObjects is not a key you can bind (you can
> only bind *to* that key), those are generated by NSArrayController
> from whatever its content is. The content can be provided by binding
> either contentSet or contentArray (not both, the result is undefined).
>
>>
>>
>> As for filter predicates... I thought doing it the way I described
>> below was the proper way since it would mean less code and more
>> reliance on binding. I guess I was wrong? :)
>>
>> Trent.
>>
>
> Yes (for the last sentence).
>
> Here's how NSArrayController works:
>
> - You provide the full content of the objects handled by
> NSArrayController by binding either contentSet or contentArray.
> - NSArrayController filters these objects according to the
> filterPredicate (either set or provided through binding) and sorts
> them according to the sortDescriptors (either set or provided through
> binding).
> - arrangedObjects is the *result* of this procedure. You can read it
> in code or bind something else to it.
>
> Christiaan
>
>> Christiaan Hofman wrote:
>>>
>>> On 25 Mar 2008, at 9:15 PM, Trent Jacobs wrote:
>>>
>>>> The app I'm writing is centered around a particular list of objects
>>>> (for example a list of items in a shop) with various filters
>>>> allowed. it's a core data app and I'm using bindings wherever
>>>> possible.
>>>>
>>>> In the model I'm using I have an entity for my objects and I've set
>>>> up relationships to the entities I'll be filtering on (for example
>>>> brand, colour, whatever).
>>>>
>>>> I've got everything with perfectly when I hook up the bindings in
>>>> IB, i.e. when I select a brand the list of objects is filtered to
>>>> only show objects of the selected brand. However, when I try to do
>>>> the bindings in code it doesn't work.
>>>>
>>>> To create the bindings I use:
>>>>
>>>> [myObjectController bind : @"contentSet"
>>>> toObject : filterController
>>>> withKeyPath : @"selection.objects"
>>>> options : nil];
>>>>
>>>> where myObjectController and filterController are NSArrayController
>>>> objects and selection.objects represents the relationship in the
>>>> model.
>>>>
>>>> This works fine. However, when I remove the contentset binding I
>>>> would expect the filtering to be removed.
>>>
>>> Why? The -unbind: method does not trigger a reload,
>>> -bind:toObject:withKeyPath:options: however does. This does make
>>> sense to me.
>>>
>>>> This doesn't happen. What happens is that the list of objects stays
>>>> the same although the controlling relationship to the filtering
>>>> array controller is gone, i.e. I change brands and the list stays
>>>> constant. To remove the bindings I am simply using:
>>>>
>>>> [myObjectController unbind : @"contentSet"];
>>>>
>>>> I think this is happening because the NSArrayController is not
>>>> being told to refresh but i can't find how to force a refresh.
>>>>
>>>
>>> -rearrangeObjects could do it. Or binding to some other property.
>>>
>>>> Any ideas?
>>>>
>>>> Thanks!
>>>
>>> Why aren't you just using filter predicates?
>>>
>>> Christiaan
>>>
>
| Related mails | Author | Date |
|---|---|---|
| Trent Jacobs | Mar 25, 21:15 | |
| Christiaan Hofman | Mar 25, 23:58 | |
| Trent Jacobs | Mar 26, 09:12 | |
| Christiaan Hofman | Mar 26, 11:27 | |
| Trent Jacobs | Mar 26, 12:00 |






Cocoa mail archive

