Import Operation

The reverse of exporting recipes is to be able to import them. The experience we’re looking for is as follows:

  1. The user receives a recipe in another application (for example, in Mail).
  2. The user taps the recipe, and it opens in our application.
  3. Our recipe application receives the data and consumes it.

To accomplish this workflow, we need to step into our UIApplicationDelegate and do a few updates.

 func​ application(_ application: ​UIApplication​, open url: ​URL​,
  sourceApplication: ​String​?, annotation: ​Any​) -> ​Bool​ {
 guard​ ​let​ controller = dataController ​else​ {
  fileToOpenURL = url
 return​ ​true
  }
 if​ controller.persistenceInitialized {
  consumeIncomingFileURL(url) ...

Get Core Data in Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.