Re: Implementing search field in core-data app
Re: Implementing search field in core-data app
- Subject: Re: Implementing search field in core-data app
- From: Matt Neuburg <email@hidden>
- Date: Fri, 08 Jan 2010 08:48:03 -0800
- Thread-topic: Implementing search field in core-data app
On Thu, 7 Jan 2010 21:14:55 +0100, Martin Hewitson
<email@hidden> said:
>Dear list,
>
>I have a fairly basic core-data model with a set of Category entities, each
category contains then a set of Item entities. What I want to do is implement a
search field which searches all items from all categories - something like the
searching is done in Mail.app.
>
>I'm not really sure how to go about this. I've tried binding the predicate
bindings of an NSSearchField to the Item array controller, but this only
searches in the items of the currently selected category (since the array
controller is bound to categorycontroller.selection.items).
>
>I also tried making another array controller which contains all items and then
set a filter predicate on this depending on the user having chosen a state: 'all
categories' or 'currently selected category'. Then I bound my table view to this
'all items array controller'. But this is not so nice since the relationship
between categories and items is not automatically handled.
>
>Is there a 'correct' way to attack such a problem, or has someone else managed
to implement a search interface something like Mail.app?
What I would suggest is not using bindings with the search field. That way,
you can respond to the user's activities in the search field in any way you
like. Take a look, for example, at my Thucydides app - it comes with source
code, and uses Core Data, and is a very small simple app so you can see
readily what's going on. We simply respond to the old-fashioned
target-action signal from the search field by building a predicate and
applying that to the controller of the full array of entities.
Another complicating factor might your notion that a category entity
"contains" a set of Item entities. This, and your statement that "the
relationship between categories and items is not automatically handled",
makes me wonder whether you've set up your Core Data model in the way that's
most appropriate for what you intend to do with this data. But the
Thucydides code won't help with that, since it has no "categories": the Core
Data model is much simpler than what you describe.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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