Re: Can CoreData return only unique results of an attribute
Re: Can CoreData return only unique results of an attribute
- Subject: Re: Can CoreData return only unique results of an attribute
- From: "Adam Gerson" <email@hidden>
- Date: Tue, 26 Feb 2008 19:34:59 -0500
Thanks for the example. What I am looking for is slightly diferent.
Lets say I have a entity called FavoriteWebsites with the attributes
name and url. The current contents of the object are
Name | URL
---------------------------------------------
Sam | http://www.aol.com
Adam | http://www.digg.com
Jane | http://www.ibm.com
John | http://www.aol.com
I want to filter for only the unique values of url, so the list I want
to get back for a separate table is
http://www.digg.com
http://www.ibm.com
http://www.aol.com
Perhaps NSPredicate is not my answer and I just need to maintain a
separate array and do some manual checking for duplicates.
On Tue, Feb 26, 2008 at 7:20 PM, Philip Bridson
<email@hidden> wrote:
> Hi there,
>
> It will only return results from itself.
>
> Its like the classic example of employee and department. If you had a table
> that you wanted to link to a list of employees you would bind to the
> employee array controller and vice versa for the department one. You cannot
> bind against the department controller for the value of, for example,
> "Employee Name". All the predicate does is filters the list based on what
> you want. e.g all employee with the name Joe. All you have to do is set the
> exact predicate in the object that you are going to bind against:
>
> - (NSPredicate *)predicate
> {
> NSString *salaryLimit = @"10000";
>
> NSPredicate *predicate = [NSPredicate predicateWithFormat @"salary > %@",
> salaryLimit];
>
> return predicate;
> }
>
> Then when you bind your filter predicate to this method in your file owner
> the array will only return objects that have a value of 10000 set in their
> salary limit key.
>
> I hope I have been of assistance.
>
> Good luck,
>
> Phil.
>
>
>
>
> On 27 Feb 2008, at 00:01, Adam Gerson wrote:
>
> I did look into NSPredicate and the Predicate Programming Guide. I
> understand the concept of filtering the ArrayController. I just didn't
> know how to write en expression asking for all unique values from the
> ArrayController for a given key. In the Predicate examples they filter
> a single potential result against some criteria. Can I say "only
> return unique values from yourself"?
>
>
> Adam
>
>
> On Tue, Feb 26, 2008 at 6:03 PM, Philip Bridson
> <email@hidden> wrote:
>
>
> Yeah there is.
>
> From the documentation:
>
>
>
> You can set a predicate for an array controller to filter the content array.
> You can set the predicate in code (using setFilterPredicate:). You can also
> bind the array controller's filterPredicate binding to a method that returns
> an NSPredicate object. The object that implements the method may be the
> File's Owner or another controller object. If you change the predicate,
> remember that you must do so in a key-value observing compliant way (see
> Key-Value Observing Programming Guide) so that the array controller updates
> itself accordingly.
>
> You can also bind the predicate binding of an NSSearchField object to the
> filterPredicate of an array controller. A search field's predicate binding
> is a multivalue binding, described in Binding Types.
>
> Or simply, create a small method in a object, such as the file owner, that
> returns a NSPredicate. Then bind the controller's filter predicate to the
> file owners predicate method. This will automatically filter your
> controllers values.
>
> Hope this helps.
>
> Phil.
>
> On 26 Feb 2008, at 22:00, Adam Gerson wrote:
>
>
>
> I have a core data object. I would like to populate a TableView with
> only the unique entires for a specific property. Clearly I could
> filter the results in code, I was wondering if there was away for core
> data and bindings to do it.
>
> Adam
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden