PDA

View Full Version : Core Data - Searching in Multiple Entities (Help Needed)




Icewind
May 30, 2006, 07:33 AM
Hi Guys,

Ok, I'm a total newbie to Mac OSX coding but have about 20 years of Wintel Dev experience in various languages. I've just started creating some nice little Cocoa Apps and ventured into Core Data. Now I'm stuck. I have a data model with two related entities (Customer and Cheques 1:M). When I auto-generate the UI by option-dragging each entity to a window, the UI is created no problem and everything works. However, each entity has it's own Search box in the UI. So, searching for customer information in the Customer's search box will retrieve customer data correctly, and the same for the Cheques search box.

What I'm trying to achieve is to only have one search box on the UI, which will search for data in BOTH entities. Can this be done? I was playing around with the predicates for each search box, but couldn't see how I can target both entities in the same predicate.

Any help would be great.



Icewind
Jun 1, 2006, 07:03 AM
I assume nobody here knows how to do this?
28 reads and no replies so far! lol :)

robbieduncan
Jun 1, 2006, 08:16 AM
Disclaimer: I don't use CoreData at the moment :D

So out of my lovely position of ignorance: I assume that the result of running the search predecate on an entity is some sort of collection (an NSArray?). So the simple solution is to run the predecate on each entity in turn and combine the output collections into one single collection.

Icewind
Jun 2, 2006, 05:55 AM
Thanks for the suggestion Robbie, I will check this out when I get back home (I'm Scottish too...an Ayrshire Farm Boy, currently working in London Mon to Fri) :rolleyes:

I will check exactly what the Search box is doing when I get home. I never thought to check what it outputs the search results to (in terms of a data structure). I know that it updates the Table View (dynamically as you type) in order to narrow down the hits, exactly the same as Spotlight, iTunes etc. So it has to be updating that data structure, whatever it is.