• 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
Re: Predicates: Trying to filter against max()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Predicates: Trying to filter against max()


  • Subject: Re: Predicates: Trying to filter against max()
  • From: Sean Murphy <email@hidden>
  • Date: Wed, 5 Apr 2006 23:43:20 -0400

On Apr 5, 2006, at 5:54 PM, Fritz Anderson wrote:

I have an entity, Bank, which contains Entrys in its relationship "table". Entry has an int attribute, "ordinal".

I want to find the Entry with the highest ordinal. I can do this by sorting an array derived from the set returned for the "table" relationship, and taking the last one; but it seems to me I should be able to filter the array with an NSPredicate like "ordinal == max (ordinal)".

Hey Fritz,

Using the NSPredicate class is usually such an awesome and amazingly simple way to filter an array, but in your case maybe you can utilize a Key-Value Coding array operator. I'm not sure if this suggestion is what you were looking for, and you probably have even thought of it already, but since the predicate language syntax is giving you so much trouble, try something like this:

	[self valueForKeyPath:@"email@hiddenal"];

This does assume allEntries is a KVC Compliant member of the current class, which might not be the approach you had in mind. This at least will give you another alternative (maybe!), instead of choosing between using predicates or sorting the array and picking out the last item. I'm not too familiar with using more advanced predicate queries, otherwise I'd try to help find a solution more in-line with your current code.

Also, I should mention that I'm actually reading your Step Into Xcode book right now (every morning with breakfast)..great work! It's definitely a nice addition to my library of Mac programming books, and I've picked up quite a bit from reading it.

I Hope this was of some help, but if not I at least was able to give you a "thumbs up" on the book!
-Sean
_______________________________________________
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
References: 
 >Predicates: Trying to filter against max() (From: Fritz Anderson <email@hidden>)

  • Prev by Date: NSTreeController, NSOutlineView + Core Data
  • Next by Date: NSXML Example Help
  • Previous by thread: Predicates: Trying to filter against max()
  • Next by thread: Re: Array operators [SOLVED]
  • Index(es):
    • Date
    • Thread