Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data app crashing when using setValue:forKey: for many-to-many relationship
    primarykey
    data
    text
    <p>I have gone over this over and over, and cannot for the life of me figure out why assigning a relationship through setValue:forKey: is not working. My method is below.</p> <pre><code>-(void)saveNewCartItemName:(NSString *)name Price:(float)price Qty:(int)qty Tax:(int)tax inCart:(NSDate *)cartDate{ NSManagedObject *newItem = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:self.appDelegate.managedObjectContext]; NSFetchRequest *query = [[NSFetchRequest alloc] initWithEntityName:@"Cart"]; NSLog(@"cartDate = %@", cartDate); [query setPredicate:[NSPredicate predicateWithFormat:@"cartDate = %@", cartDate]]; NSError *error; NSMutableArray *queryResults = [[self.appDelegate.managedObjectContext executeFetchRequest:query error:&amp;error] mutableCopy]; NSLog(@"queryResults count = %d", [queryResults count]); if ([queryResults count] == 1) [newItem setValue:[queryResults objectAtIndex:0] forKey:@"cartThatHasItem"]; [newItem setValue:name forKey:@"itemName"]; [newItem setValue:[NSNumber numberWithFloat:price] forKey:@"itemPrice"]; [newItem setValue:[NSNumber numberWithInt:qty] forKey:@"itemQty"]; [newItem setValue:[NSNumber numberWithInt:tax] forKey:@"itemTax"]; [self.appDelegate.managedObjectContext save:&amp;error]; } </code></pre> <p>The line that it crashes on every time is:</p> <pre><code>if ([queryResults count] == 1) [newItem setValue:[queryResults objectAtIndex:0] forKey:@"cartThatHasItem"]; </code></pre> <p>My NSLog shows that there is a NSManagedObject to assign the relationship to, and I have double checked the name in the forKey: that there are no typos. All that Xcode tells me is that it prints out '(null)' on my console and then tells me 'libc++abi.dylib: terminate called throwing an exception' on the next line.</p> <p>Why is it crashing? And how do I fix it?</p> <p>Update: That's the entire error message.</p> <pre><code>2012-07-03 18:28:57.844 appName[3063:11603] (null) libc++abi.dylib: terminate called throwing an exception (lldb) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload