Question

In my entity model I have a top-level "Installation" entity, which has a child "cards" relationship. I also have a "Person" entity, which has a child "cards" relationship.

I've written some code which will sort the NSSet of cards to return a specific subset (called sortedCards), and this function can be performed at either the Installation level, or at the Person level.

For exmaple, I want to be able to call:

NSArray *cards = [installation sortedCards];

as well as:

NSArray *cards = [person sortedCards];

Where am I supposed to put this code so that I don't copy the code in two places? I started by putting it in the Installation NSManagedObject category that I created. But if I do that, i need to copy the code into the Person category as well.

Should I put in an NSSet category and call [installation.cards sortedCards] and [person.cards sortedCards]? That doesn't feel right either.

Any help much appreciated.

Duncan

Was it helpful?

Solution

You should place this method in NSSet category, because categories are used for extending basic functionality. And if you need sort NSSet in different places, it should be NSSet category work, not other object or class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top