Re: Finding the largest value in an NSTreeController?
Re: Finding the largest value in an NSTreeController?
- Subject: Re: Finding the largest value in an NSTreeController?
- From: Jonathan Dann <email@hidden>
- Date: Sat, 31 May 2008 21:26:02 +0100
On 31 May 2008, at 19:47, Rick Mann wrote:
Jonathan, thank you for the excellent example on working with the
containers. That will certainly be useful.
You're welcome, but I apologise, I forgot the -rootNodes method that
one of the tree controller methods I sent you calls! This method
returns the top-level objects in the tree (NSTreeController.h assures
me that -arrangedObjects responds to -childNodes, this differs from
what the docs say).
// NSTreeController_Extensions
- (NSArray *)rootNodes;
{
return [[self arrangedObjects] childNodes];
}
now it'll work!.
On May 31, 2008, at 12:05:58, I. Savant wrote:
1 - Create a fetch request for your desired entity.
2 - Create a sort descriptor for the key whose max value you're
interested in.
3 - Set the fetch request's sort descriptor to the above.
4 - Create any predicates needed for filtration (ie, whatever you
may or may not have used in the tree controller).
5 - Set the fetch request's predicate to the above if any.
6 - Execute the fetch request and get the last (or first) object of
the results (checking for errors, minding the set-versus-array
gotchas, etc.).
Wow, really? No way to just get at all the items in the tree
controller with some key path, then use @max?
Think of this this way, only the tree controller knows which objects
it has in it. The context and the model objects are ignorant of
this. The entity you fetch is that you set in IB for the tree
controller, so that is *kind of* asking the context, "get me the nodes
in the tree controller", but not exactly as the tree controller itself
may have a predicate that causes it to fetch only some of those types
of entities. The fetch request (if you set the same predicate as the
you have for the tree controller) will get you your NSSet of objects,
then you can do whatever you want with the objects.
HTH,
Jon
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden