title: +entityForName: could not locate an entity named 'EntityName' in this model
body: <p><strong><em>I know this may look as a duplicate but I tried several answers and all of those did not work.</em></strong></p>
  
  <p>I am trying to use Core Data to store which levels are completed, but I am running in some trouble saving the data. At the moment dat a level is completed the following lines are called. </p>
  
  <pre><code>    let appDelegate =
          UIApplication.shared().delegate as! AppDelegate
  
  
      let managedContext = appDelegate.managedObjectContext
  
  
      let level = NSEntityDescription.insertNewObject(forEntityName:"SucceededLevels", into:managedContext) as NSManagedObject
  
  
      person.setValue(levelName, forKey: "levels")
  
      do {
  
          try managedContext.save()
  
          levelsArray.append(person)
      } catch let error as NSError  {
          print("Could not save \(error), \(error.userInfo)")
      }
  </code></pre>
  
  <p>But I am getting the following error </p>
  
  <blockquote>
    <p>"Terminating app due to uncaught exception
    'NSInternalInconsistencyException', reason: '+entityForName: could not
    locate an entity named 'SucceededLevels' in this model."</p>
  </blockquote>
  
  <p>I have set up the entity in the .xcdatamodel.</p>