• 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: Predicate for Array Controller - only parents with children - SOLVED
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Predicate for Array Controller - only parents with children - SOLVED


  • Subject: Re: Predicate for Array Controller - only parents with children - SOLVED
  • From: Steve Cronin <email@hidden>
  • Date: Sat, 24 Mar 2007 12:01:09 -0500

Folks;

Tim wrote:

As for the unresolved keypath, I think it is the case that if the object being searched is based on a CoreData entity, then predicates and bindings work only on attributes of the entity. You cannot use arbitrarily computed functions. As I recall, this is because predicates and bindings are operating at the SQL level, which knows nothing about your application code. In your case, you would need to add something like a temporary attribute, "hasChildren". Then you can write Objective-C code to support the value of the attribute.

So I added a transient attribute to the model and got it to work with the following added comments:
The Predicate builder on the 'Attribute' pane in IB seems to require a non-transient attribute.
Even after adding the attribute to the MOM I would get the 'unresolved keyPath' error when utilizing the new transient attribute in this predicate.


BUT if I bind the filterPredicate to a method in the window controller it WILL work.
I must say this nuance eludes my understanding! Where exactly will transients work? Where is this documented?


The transient was defined as a Boolean which is in fact an NSNumber (an object) so the class method is:
- (NSNumber *) hasChildren { return [NSNumber numberWithInt:([[self valueForKeyPath:@"childrens.@count"] intValue] > 0)]; }



The windowController method is:
- (NSPredicate *) hasChildren { return [NSPredicate predicateWithFormat:@"hasChildren == TRUE" ]; } //NOTE: either TRUE or 1 will work here


Nib load time is within expected range


Finally, sometimes you may get much better performance by writing your own filter code rather than relying on NSPredicate, especially when relationships are involved. NSPredicate can generate an astounding number of supernumerary fetches.

OK this sounds interesting but I do not understand what you mean by "..writing your own filter code".
Could you expand on that topic just a bit?


mmalc - Thanks for the pointer on pre-binding! I will try and digest and move that knowledge into my main memory.
At this point I don't think it is appropriate for the usage here.
I am loading up a whole series of contextual arrays for UI support which are not yet based on user selected values.


Thank-you both for the help!  Cocoa-Dev Rocks!
Steve
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >Predicate for Array Controller - only parents with children (From: Steve Cronin <email@hidden>)
 >Re: Predicate for Array Controller - only parents with children (From: Timothy Larkin <email@hidden>)

  • Prev by Date: Re: NSString initWithUTF8String - crazy retainCount with empty string
  • Next by Date: Re: NSString initWithUTF8String - crazy retainCount with empty string
  • Previous by thread: Re: Predicate for Array Controller - only parents with children
  • Next by thread: How to access built-in English dictionary?
  • Index(es):
    • Date
    • Thread