title: Programmatically adding to a Core Data entity (like IB binding 'add')
body: <p>I have a core data model with an entity called <strong>clients</strong> that is made up of the following attributes:</p>
  
  <p><img src="https://i.stack.imgur.com/V08pT.png" alt="client model entity"></p>
  
  <p>If I click on an '<strong>add client</strong>' button and bring up the following window:</p>
  
  <p><img src="https://i.stack.imgur.com/Pg3BL.png" alt="client window"></p>
  
  <p>what would be the correct method to programmatically add a new entry for each property simultaneously (in a similar fashion to how a bound IB 'add' button would work with an <code>NSArrayController</code>) and have them appear in the textfields of the '<strong>add client</strong>' window to edit? The textfields in the '<strong>add client</strong>' window are bound to the corresponding properties (with one or two still missing) of the <strong>client</strong> entity. The code I have at the moment is:</p>
  
  <pre><code>- (IBAction)addNewClient:(id)sender;
  {
      [addClientsWindow makeKeyAndOrderFront:self];
      //NSManagedObjectContext *clientsMoc= [clientsController managedObjectContext];
      //[clientsMoc addObject:[clientsMoc newObject]];
      [clientsController addObject:[clientsController newObject]];
  }
  </code></pre>
  
  <p>Which worked for other entities in this project but isn't working for <strong>client</strong> since I added relationship types (it throws up KVC errors in the console). I imagine it's because I am addressing the <code>NSArrayController</code> rather than the <code>NSManagedObjectContext</code> but the commented out code isn't working for me. This attempt follows on from a <a href="https://stackoverflow.com/questions/5050732/specifying-which-object-to-get-the-super-of">previous question</a> as the question has changed a lot and I'm struggling to implement the advice given. I really need a good starting point and the apple dev docs aren't helping me make sense of this.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>---- Update ----</strong></p>
  
  <p>Am I explaining things badly in this question? I'm new here but thought there might be an attempt at an answer. Googling this was hard for some reason. I may have found something similar to a solution through an unrelated Google search. Luckily it was relevant to this.</p>
  
  <pre><code>- (IBAction)addNewClient:(id)sender;
  {
      [addClientsWindow makeKeyAndOrderFront:self];
      NSManagedObjectContext *clientsMoc= [clientsController managedObjectContext];
      NSManagedObject *clientsEntity = [NSEntityDescription
                                       insertNewObjectForEntityForName:@"Clients" 
                                         inManagedObjectContext:clientsMoc];
      [clientsEntity setValue:@"name" forKey:@"clientName"];
      [clientsEntity setValue:@"company" forKey:@"clientCompany"];
      [clientsEntity setValue:@"address" forKey:@"clientAddress"];
      [clientsEntity setValue:@"11111111" forKey:@"clientLandline"];
      [clientsEntity setValue:@"email@gmail.com" forKey:@"clientEmail"];
  }
  </code></pre>
  
  <p>This created a full new entry for the clients entity - I didn't realise I would have to do an individual value for each property. The KVC errors continued though and I couldn't find a solution at all. Apple dev docs were actually helpful on this one, <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Concepts/Troubleshooting.html" rel="nofollow noreferrer">here</a>, and adding <code>NSBindingDebugLogLevel 1</code> to the “Arguments to be passed at launch” list gave me details of exactly what was causing the problem. It was an old binding to an <code>NSTableColumn</code> that hadn't been updated.</p>