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

Predicate for Array Controller - only parents with children


  • Subject: Predicate for Array Controller - only parents with children
  • From: Steve Cronin <email@hidden>
  • Date: Sat, 24 Mar 2007 03:00:55 -0500

Folks;

I'm trying to figure the optimal way to specify an ArrayController for a CoreData entity 'Parent'.

The rub is that I want to load only those Parents who have a relationship with at least one Child entity.
(Note the relationship name is children)


To me it doesn't seem that I should have to declare an attribute in the data model for this purpose, but read on dear reader!

In IB on the 'Attribute' pane for the ArrayController I set the entity to 'Parent' and in the Predicate Editor below I set the predicate to:
children.@count > 0
With this construct when the nib is loading it will peg out the CPU and just thrash -> no error just total redline
It will eventually complete, in my case it takes 4 minutes to load the nib!! (~700 Parent records) User won't like this!


OK so I remove this predicate from the 'Attribute' pane and then switch to the 'Bindings' pane where I bind the Array Controller's 'FilterPredicate's ModelKeyPath to a 'hasChildren' in the windowController
- (NSPredicate *) hasChildren {return [NSPredicate predicateWithFormat:@"children.@count > 0" ];}
Same result


BTW: If I merely remove the predicate and just load all Parent records, the nib loads in ~20 seconds.
Still sucky I know but there's a lot of debug code at this point and I'm not a premature optimizer =;-)


OK so now off to the Parent class where i implement a method (no attribute added to the data model):
- (BOOL) hasChildren {
if ( [self valueForKeyPath:@"children.@count"] > 0 ) {
return TRUE;
} else return FALSE;
}


I go back to the original 'Attribute' pane of the ArrayController and set the Predicate to 'hasChildren == 1' -->
*** NSRunLoop ignoring exception 'unresolved keypath: hasChildren' that raised during posting of delayed perform with target 4f083a0 and selector 'invokeWithTarget:'
BTW: It doesn't change the result if I add a null setter for this setHasChildren.


Just for grins I remove this predicate and re-bind the filterPredicate to a revised version of the 'hasChildren' method in the windowController:
- (NSPredicate *) hasChildren {return [NSPredicate predicateWithFormat:@"hasLocations == TRUE" ];}
Back to the 4 minute load


At this point I'm thinking I must add an attribute to the data model but my gut just won't let me do it!

Can somebody shed light on how I can efficiently load an array of Parent entities where these instances have a least one Child.!!

Thanks a bunch for any insights!
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


  • Follow-Ups:
    • Re: Predicate for Array Controller - only parents with children
      • From: Timothy Larkin <email@hidden>
    • Re: Predicate for Array Controller - only parents with children
      • From: mmalc crawford <email@hidden>
  • Prev by Date: Re: NSTable and custom NSCell issues
  • Next by Date: Re: Predicate for Array Controller - only parents with children
  • Previous by thread: [SOLVED] Re: Compositing shrunk cells
  • Next by thread: Re: Predicate for Array Controller - only parents with children
  • Index(es):
    • Date
    • Thread