Using NSPredicate to query a Core Data to-many relationship

Discussion in 'Mac Programming' started by MacDonaldsd, Dec 19, 2009.

  1. macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #1
    Hi,

    I am trying to use NSPredicate to query a CoreData to-many relationship, but it errors, as it is calling it on the NSMutableSet, and not the objects themselves.

    My "item" has a to-many relationship called "tags" and each tag has a name property which is an NSString.

    Im trying to create an NSPredicate that sees if ANY of the Tag's name property, matches a given string.

    I have tried using "ANY tags.name MATCHES[c] %@" but I get the error

    [<_NSFaultingMutableSet 0x1005708f0> addObserver:forKeyPath:eek:ptions:context:] is not supported. Key path: name


    Any ideas are greatly appreciated, as Im a bit stuck.

    Cheers
     
  2. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    Probably the %@ needs to be in quotations. i.e. the predicate should be of the form: "ANY tags.name MATCHES[c] \"%@\""
     
  3. thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #3
    Hi Eraserhead,

    NSPredicate does the quotes for me :D

    It seems if I do it in code using an NSFetchRequest it works, but if I set the filter predicate on a NSArrayController it fails.
     
  4. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #4
    <shrug> I've always used quotes like that in my code.
     

Share This Page