title: Swift: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Test''
body: <p>I will use CoreData for the first time.<br>
  However, the following code causes an error.<br>
  I would like to try saving the data, but it is "nilError".<br>
  Could you tell me how to solve it?<br></p>
  
  <pre><code>func testCoreData(){
      /// Base
      let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate
      let context = appDelegate.persistentContainer.viewContext
  
      /// set
  
      /// Error Log
      /**
        * Ok!!Save. id=fdsafdsfadf
        * 2018-09-08 **:**:**.*****+0*** **[**:**] 
        * *** Terminating app due to uncaught exception 
        * 'NSInvalidArgumentException', reason: '+entityFo
        * rName: nil is not a legal NSManagedObjectContext 
        * parameter searching for entity name 'Test''
      */
  
      print("Ok!!Save. id=fdsafdsfadf")
      let entity = NSEntityDescription.entity(forEntityName: "Test", in: context)
      let newData = NSManagedObject(entity: entity!, insertInto: context)
      newData.setValue("fdsafdsfadf", forKey: "id")
      do{
          try context.save()
      }catch{
          print(error)
      }
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/bDjBq.png" alt="The Image of .xcdatamodeld"></p>