• 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: NSPredicate/NSExpression - can they solve this Core Data problem?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPredicate/NSExpression - can they solve this Core Data problem?


  • Subject: Re: NSPredicate/NSExpression - can they solve this Core Data problem?
  • From: David Hoerl <email@hidden>
  • Date: Fri, 02 Apr 2010 16:30:13 -0400

Having the array of attributes unrolled separately is a little odd.  Do you mean you have an array of attribute names from, say the entity, and you want to ask a MO for all its non-nil attribute values and get back an array of matching attribute names for those non-nil values?

- Ben

Specifically, here is what I'm trying to do:

I have a NSManagedObject "Address" (and no treecontroller) that has properties - lets say name, homePhone, and workPhone. workPhone is optional.

So, one Address record has obj.name = "Joe Blow", obj.homePhone = "555-1212" and obj.workPhone = nil

I put the Address object's property keys in an NSArray *attributes = { @"name", @"homePhone", @"workPhone" )

The exercise is to reduce the attribute array to just the set of keys that when applied to the object result in a value - that is, not nil.

I know this is quite easy to do in code (I'm doing it now) - but I tried and tried to construct some bizarre looking NSExpressions and Predicates to fit into this:

attributes = [attributes filteredArrayWithPredicate:[some predicate]];

The problem is constructing a predicate where the "target" is really the base object, and the keys are applied one by one against this target (think a NSExpression using a keyPath], and the result is a smaller array.

I suspect it can be done but have not figured out how to do it yet. The stumbling block is that the target for most expressions will be the keys, one at a time, where it would be best if instead of a target, it was a parameter.

Again, this is an intellectual exercise.

David
_______________________________________________

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


  • Follow-Ups:
    • Re: NSPredicate/NSExpression - can they solve this Core Data problem?
      • From: Ben Trumbull <email@hidden>
References: 
 >re: NSPredicate/NSExpression - can they solve this Core Data problem? (From: Ben Trumbull <email@hidden>)

  • Prev by Date: Re: Creating WebView in code
  • Next by Date: Re: MutableArray losing contents
  • Previous by thread: re: NSPredicate/NSExpression - can they solve this Core Data problem?
  • Next by thread: Re: NSPredicate/NSExpression - can they solve this Core Data problem?
  • Index(es):
    • Date
    • Thread