Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data Programmatically Adding a to-many Relationship
    text
    copied!<p>I have an entity Item, and an entity Type (that has an attribute "Name") in a to-many relationship with Item. (Ie: Item: Brown Table, related to Type with Name "Coffee Table").</p> <p>I've programmatically added new Items fine, using, for example: </p> <pre><code>[newItem setValue:([nameTextField stringValue]) forKey:@"Name"]; [newItem setValue:(costNumber) forKey:@"Cost"]; [newItem setValue:(priceNumber) forKey:@"Price"]; </code></pre> <p>I've been searching for hours but can't find something that works for me adding a relationship to the new item. I'm using a NSPopUpButton to choose the Type of the item, and have tried methods like selectedItem, selectedTag, and selectedCell. I'm trying to get values from my "typeArray", which is filled as follows:</p> <pre><code>NSFetchRequest *fetchRequest2 = [[NSFetchRequest alloc] init]; NSEntityDescription *entity2 = [NSEntityDescription entityForName:@"Type" inManagedObjectContext:managedObjectContext]; [fetchRequest2 setEntity:entity2]; NSError *error = nil; typeArray = [managedObjectContext executeFetchRequest:fetchRequest2 error:&amp;error]; if (typeArray == nil) { NSLog(@"ERROR"); } [fetchRequest2 release]; </code></pre> <p>I'm not sure if the following is along the right lines:</p> <pre><code>NSManagedObject *selectedType = [typeArray objectAtIndex:[typePopUpButton selectedTag]]; </code></pre> <p>But then I have no option for selectedType to add something like "addObject"..</p> <p>Any help appreciated, thank you.</p>
 

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