title: How to Save Entity with Relationship in Core Data
body: <p><em>I'm new to Core Data, so go easy on me. :) I'm currently using iOS 7 in Xcode 5.</em></p>
  
  <p>I have two Entities: <strong>Aircraft</strong> and <strong>Entry</strong>. There is a <strong>one aircraft</strong> to <strong>many entry</strong> relationship.</p>
  
  <p>I'm trying to save a new Entry which has an aircraft object in it. Here is my <code>Entry.h</code> file (minus the <code>#import</code>):</p>
  
  <pre><code>//  Entry.h
  @class Aircraft;
  
  @interface Entry : NSManagedObject
    @property (nonatomic, retain) NSNumber *duration;
    @property (nonatomic, retain) NSDate *flightDate;
    @property (nonatomic, retain) Aircraft *aircraft;
  @end
  </code></pre>
  
  <p>Meanwhile, over in my view controller where I save the new Entry, I have the following code. I use a dictionary to set up my data prior to creating a new record:</p>
  
  <pre><code>//Add New Entry
  Aircraft *aircraft = [Aircraft new];
  aircraft.aircraftRegistration = _aircraftRegistrationTextField.text;
  
  NSDictionary *newEntry = @{
    @"aircraft": aircraft, //???
    @"flightDate": [formatter dateFromString:_flightDateTextField.text],
    @"duration": [PPHelpers convertHHMMtoDecimal:_durationTextField.text],
  };
  
  //Save new Entry to Core Data
  PPAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  NSManagedObjectContext *context = [appDelegate managedObjectContext];
  
  NSManagedObject *item = [NSEntityDescription insertNewObjectForEntityForName:@"Entry" inManagedObjectContext:context];
  
  [item setValuesForKeysWithDictionary:newEntry];
  
  NSError *error;
  [context save:&amp;error];
  </code></pre>
  
  <p>I get a couple errors from this:</p>
  
  <p><code>CoreData: error: Failed to call designated initializer on NSManagedObject class 'Aircraft'</code></p>
  
  <p>and...</p>
  
  <p><code>-[Aircraft setAircraftRegistration:]: unrecognized selector sent to instance 0x110b0b550</code></p>
  
  <p>I suspect the issue is that I'm not adding the Aircraft to the Entry in the right way. </p>
  
  <p>Any ideas what I'm doing wrong?</p>