Looking for an elegant way to store one-to-many relationship in coredata when order is important

Posted by Eric Schweichler on Stack Overflow See other posts from Stack Overflow or by Eric Schweichler
Published on 2010-03-20T17:53:27Z Indexed on 2010/03/20 20:51 UTC
Read the original article Hit count: 322

I've been trying to come up with a way to solve my problem, but every solution I can think of is messy and makes me want to retch.

I have a one-to-many relationship, consisting of a Team object that can have many Member objects. When I built my data model using Xcode, I was given the default NSSet in which to store the member objects, Unfortunately Sets are not ordered and I need to preserve the order of the Member objects and I need to know if there are empty spaces between Members.

I thought of Using an NSArray in place of the NSSet and creating a dummy Member object in my data store that I could use to mark vacant a spot between to Member objects, but that solution really feels like too much of a hack to me. Since I'll always have to filter out this dummy Member from any queries.

An NSDictionary would be perfect as I could store the Member object references and their positions as Object-Key pairs, (taking care of both order and vacancies) but apparently CoreData does not support NSDictionary.

Has anyone had a similar need, and devised a simple solution?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about coredata