title: viewContext is not getting saved in the database (app.sqlite)
body: <p>I created a app to save the details of a student, using NSPersistanceContainer and while I'm getting the data from JSON and saving to db, at that time I'm getting fetch results count &gt; 0. If I restarted the app the fetch result count returns 0.</p>
  <pre><code>lazy var persistentContainer: NSPersistentContainer = {
  
      let container = NSPersistentContainer(name: &quot;Students_dev&quot;)
  
      let storeURL = try! FileManager
          .default
          .url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
          .appendingPathComponent(&quot;Students_dev.sqlite&quot;)
      print(&quot;URL :&quot;,storeURL)
  
      let storeDescription = NSPersistentStoreDescription(url: storeURL)
      storeDescription.shouldMigrateStoreAutomatically = true
      storeDescription.shouldMigrateStoreAutomatically = true
      container.viewContext.automaticallyMergesChangesFromParent = true
      container.persistentStoreDescriptions = [storeDescription]
  
      container.loadPersistentStores(completionHandler: { (storeDescription, error) in
          if let error = error as NSError? {
              fatalError(&quot;Unresolved error \(error), \(error.userInfo)&quot;)
          }
      })
      return container
  }()
  
  // MARK: - Core Data Saving support
  
  func saveContext (context: NSManagedObjectContext) {
     
     persistentContainer.performBackgroundTask({ (context) in
          if context.hasChanges {
              do {
                  try context.save()
              } catch {
                  let nserror = error as NSError
                  fatalError(&quot;Unresolved error \(nserror), \(nserror.userInfo)&quot;)
              }
          }
      })
  }
  </code></pre>
  <p>The context is not empty while I'm saving to db, when I check the sqlite file the table is empty. Didn't get what's is missing from my side.</p>
  <p><strong>No data is being get inserted into SQL file</strong>
  <a href="https://i.stack.imgur.com/K2x2E.png" rel="noreferrer"><img src="https://i.stack.imgur.com/K2x2E.png" alt="screenshot of sql log" /></a></p>