• 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
[Leopard] SUBQUERY predicate with CoreData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Leopard] SUBQUERY predicate with CoreData


  • Subject: [Leopard] SUBQUERY predicate with CoreData
  • From: "Barry Wark" <email@hidden>
  • Date: Mon, 4 Feb 2008 14:02:57 -0800

I have an example CoreData managed object model that contains an
entity Foo{fooProp:string; keyValues:{to- m,eany relationship to
KeyValue}) and an entity KeyValue(key:string,value:float; foo:{to-one
relationship to Foo}). I'm having trouble executing a fetch request
with a predicate that contains a SUBQUERY expression on a managed
object context using this model. I've included the .xcdatamodel (zip'd
with an added extension -- hopefully it will make it pass the list
filter). In the Xcode "CoreData application", using the included
.xcdatamodel and adding this method to the app delegate:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    // add some examples to the XML store
    id foo = [NSEntityDescription insertNewObjectForEntityForName:@"Foo"

inManagedObjectContext:[self managedObjectContext]];
    [foo setFooProp:@"fooProp1"];

    id kv = [NSEntityDescription insertNewObjectForEntityForName:@"KeyValue"
                                          inManagedObjectContext:[self
managedObjectContext]];

    [kv setKey:@"key1"];
    [kv setValue:[NSNumber numberWithFloat:1.0] forKey:@"floatValue"];

    [foo addKeyValuesObject:kv];

    foo = [NSEntityDescription insertNewObjectForEntityForName:@"Foo"

inManagedObjectContext:[self managedObjectContext]];
    [foo setFooProp:@"fooProp2"];

    kv = [NSEntityDescription insertNewObjectForEntityForName:@"KeyValue"
                                          inManagedObjectContext:[self
managedObjectContext]];

    [kv setKey:@"key2"];
    [kv setValue:[NSNumber numberWithFloat:2.0] forKey:@"floatValue"];

    [foo addKeyValuesObject:kv];


    NSFetchRequest *fetch = [[[NSFetchRequest alloc] init] autorelease];
    [fetch setEntity:[NSEntityDescription entityForName:@"Foo"
                                 inManagedObjectContext:[self
managedObjectContext]]];

    [fetch setPredicate:[NSPredicate
predicateWithFormat:@"(SUBQUERY(self.keyValues, $kv, $kv.key like
'key1' && $kv.floatValue==1.0).count > 0) && fooProp like
'fooProp1'"]];

    id result = [[self managedObjectContext] executeFetchRequest:fetch

error:nil]; //app crashes here

    NSLog(@"%@", result);

}

produces the following (relevant) output at the console

*** -[NSCFArray compare:]: unrecognized selector sent to instance 0x195220

and the application crashes during the  [[self managedObjectContext]
executeFetchRequest:fetch error:nil] method.

I know the documentation on using SUBQUERY is still on the way, but I
was hoping that one of the CoreData gurus could suggest what I'm doing
wrong.

Thanks!

Barry

Attachment: SubqueryLab_DataModel.xcdatamodel.zip.safe
Description: Binary data

_______________________________________________

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: [Leopard] SUBQUERY predicate with CoreData
      • From: "Melissa J. Turner" <email@hidden>
  • Prev by Date: PDFAnnotationLine problem
  • Next by Date: Re: copyCGLContextForPixelFormat
  • Previous by thread: Re: PDFAnnotationLine problem
  • Next by thread: Re: [Leopard] SUBQUERY predicate with CoreData
  • Index(es):
    • Date
    • Thread