Skip to content

Instantly share code, notes, and snippets.

@acwright
Last active October 23, 2021 01:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acwright/17f65e965d03da153fe67dcc1143213b to your computer and use it in GitHub Desktop.
Save acwright/17f65e965d03da153fe67dcc1143213b to your computer and use it in GitHub Desktop.
fileImporter
.fileImporter(
isPresented: $isImporting,
allowedContentTypes: [.plainText],
allowsMultipleSelection: false
) { result in
do {
guard let selectedFile: URL = try result.get().first else { return }
guard let message = String(data: try Data(contentsOf: selectedFile), encoding: .utf8) else { return }
document.message = message
} catch {
// Handle failure.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment