• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTreeController / CoreData quesiton
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTreeController / CoreData quesiton


  • Subject: NSTreeController / CoreData quesiton
  • From: Justin Fagnani <email@hidden>
  • Date: Tue, 24 May 2005 13:48:08 -0700

I'm wondering how to model and bind this particular scenario...

I have some hierarchical data with two classes: Category and Item. Categories are nested and have only one parent, Items belong to only one Category. Eventually I want an NSBrowser to contain the Categories and a table to show all the items that are descendants of the selected Category(s).

So far my model looks like this:

Category
parent <<--> Category (inverse w/ children)
children <-->> Category
items <-->> Item (inverse with Item.category)

Item
category <<--> Category

I have a NSTreeController setup with a predicate of parent == nil and that seems to work pretty well. The problem is getting all the correct items. I can get the direct items of the selected Category, but not the Items it's child categories contain, and so on.

I'm thinking that Category.items maybe should be a fetched property instead of a relationship, but I don't know how to write a predicate that says "category or category.parent or category.parent.parent... == selectedCategory". I'm actually not too sure how to directly compare objects, I'm just using names.

here's my other ideas:

*Subclass NSManagedObject for Category and use a recursive method for getting all the items.
*Do the same for Item, but it returns all ancestor categories as a set. This could maybe be used in a predicate like "selectCategory IN item.categoryPath" (though l'm not sure I can even get the selected category into a predicate statement)
*Have Item.category be a to-many relationship that links to it's direct category and all it's ancestors, but this seems fragile.


Any thoughts?

Thanks,
  Justin

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTreeController / CoreData quesiton
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: AppleScript: Returning object references in Cocoa
  • Next by Date: Re: xCode fetch predicate view
  • Previous by thread: Suppress "Bring All to Front" menu item in Window menu?
  • Next by thread: Re: NSTreeController / CoreData quesiton
  • Index(es):
    • Date
    • Thread