filter data that i loaded with core data with NSSearchField

Go To StackoverFlow.com

2

How can i use NSSearchField for filter data that i load into program with core data ?

i want to do that from code not in interface with binding

(please give me tutorial about it)

2012-04-05 15:06
by SajjadZare


1

There is probably not a more authoritative expert (outside of Apple) on Core Data than the folks at cimgf.com. Here's a tutorial that should help you accomplish exactly what you need.

http://www.cimgf.com/2008/11/25/adding-itunes-style-search-to-your-core-data-application/

EDIT: You can further filter the data without going back to disk by using another NSPredicate on the array. If you have a NSFetchedResultsController called myFetchController and a NSPredicate named myPredicate you can do the following.

NSArray * results = [myFecthController fetchedObjects];
NSArray * filteredResults = [results filteredArrayUsingPredicate:myPredicate];
2012-04-05 19:02
by Jeff Wolski
thank you.in this example each time that we want to filter data we set predicate to array controller,does array controller reload data from persistence store - SajjadZare 2012-04-05 20:07
It is possible to filter what is already in the fetchedResults array. However, if you change the NSPredicate and perform the fetch again, the results will be loaded again from the persistent store - Jeff Wolski 2012-04-05 20:16
in this example how can i do it that the result doesn't reload from persistent store (because of time for accessing disk - SajjadZare 2012-04-06 02:32
You can also speed things up dramatically by indexing the attribute on which you're filtering - Jeff Wolski 2012-04-06 03:36


1

I think what you're looking for is information on using a predicate with an NSFetchRequest.

See Apple's Documentation on predicate programming.

No? Well have you been to Apple's documentation on search fields?

2012-04-05 15:22
by DRVic
no,i want to do that with nssearchfield, i load all of data from persistent store to program and hold them in nsmutablearray,now i want to filter them with search fiel - SajjadZare 2012-04-05 15:26
Oh, so core data was just a red herring. Added another link to the answer - DRVic 2012-04-05 15:27
Ads