title: iOS 8 Swift - saving data of multiple entities
body: <p>I have the following entity relationship for my practice app.</p>
  
  <p><img src="https://i.stack.imgur.com/ksx9A.png" alt="entity relationship"></p>
  
  <p>And I'm stuck with the saving part of a new recipe that consists of multiple entities.</p>
  
  <p>The reason I have RecipeIngredient intermediate(joint) entity is that I need an additional attribute that will store a varying amount of an ingredient by recipe.</p>
  
  <p>Here is the implementation which is obviously missing the assignment of the amount value to each new ingredient as I was not certain about the need for initialising this RecipeIngredient entity or even if I did, I wouldn't know how to glue them all up as one recipe. </p>
  
  <pre><code>@IBAction func saveTapped(sender: UIBarButtonItem) {
  
      // Reference to our app delegate
      let appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
  
      // Reference moc
      let context: NSManagedObjectContext = appDel.managedObjectContext!
      let recipe = NSEntityDescription.entityForName("Recipe", inManagedObjectContext: context)
      let ingredient = NSEntityDescription.entityForName("Ingredient", inManagedObjectContext: context)
  
  
      // Create instance of data model and initialise
      var newRecipe = Recipe(entity: recipe!, insertIntoManagedObjectContext: context)
      var newIngredient = Ingredient(entity: ingredient!, insertIntoManagedObjectContext: context)
  
      // Map properties
      newRecipe.title = textFieldTitle.text
      newIngredient.name = textViewIngredient.text
  
      ...
  
      // Save Form
      context.save(nil)
  
      // Navigate back to root vc
      self.navigationController?.popToRootViewControllerAnimated(true)
  
  }
  </code></pre>