title: Backup and restore CoreData
body: <p>I would like to offer my users the possibility to email a backup of their data:</p>
  
  <pre><code>let filemanager = FileManager()
  let documentsPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
  let coreDataFilePath = documentsPath.appending("/Application Support/MyApp.sqlite")
  let coreDataFile = filemanager.contents(atPath: coreDataFilePath)
  print("\(coreDataFilePath)")
  
  if MFMailComposeViewController.canSendMail()
  {
      let mail = MFMailComposeViewController()
      mail.mailComposeDelegate = self
      mail.setSubject("Backup")
      mail.setMessageBody("Use this email to backup your data", isHTML: true)
      mail.addAttachmentData(coreDataFile!, mimeType: "myapp/sqlite", fileName: "myapp.madb")
  
      present(mail, animated: true, completion: nil)
  }
  else
  {
      print("Mail services are not available. Please open the mail application and setup an email account.")
      return
  }
  </code></pre>
  
  <p>But I'd like to restore the data and don't know how I should go about this. Especially that iOS 10 CoreData has changed.
  And I'd like to do all of this without having to have to user restart the app.</p>
  
  <p>I have this post as reference:
      <a href="https://stackoverflow.com/questions/3364240/best-practices-for-core-data-store-sqlite-backup?rq=1">Best practices for core data store (sqlite) backup?</a></p>