views:

15

answers:

1

I want to load a client object and then pull their related purchase orders based on whether they have been placed or not, purchase orders have an IsPlaced BOOL property.

So I have my client object and I can get all purchase orders like this, which is working great:

purchaseordersList =[[myclient.purchaseorders allObjects] mutableCopy];

But ideally I would actually like 2 array's - one for each order type: IsPlaced=YES and IsPlaced=NO

How do I do that here? Or do I need to do another fetch?

A: 

First, there is no reason to be turning the set into an array unless you are sorting it and there is no reason to be turning that array into a mutable array. Did you get that from some example code?

Second, you can filter an array or a set by using a predicate so you can create two sets (or arrays) easily via:

NSSet *placed = [[myclient purchaseorders] filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"isPlaced == YES"]];
NSSet *notPlaced = [[myclient purchaseorders] filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"isPlaced == YES"]];

If you are wanting to use this for a UITableView then look into a NSFetchedResultsController instead. It will save you a LOT of boiler-plate code.

Do you remember what example code you got that from? Been seeing that -mutableCopy a lot lately and would love to quash it. :)

Marcus S. Zarra
sweet, yep - just learning from bad example code I guess. So can I go through and NSSet just like and array to populate a UITableView?
Slee