Skip to content

Instantly share code, notes, and snippets.

@tkausch
Created October 23, 2020 14:57
Show Gist options
  • Save tkausch/29fa0bf14589b36244833861267bf70c to your computer and use it in GitHub Desktop.
Save tkausch/29fa0bf14589b36244833861267bf70c to your computer and use it in GitHub Desktop.
How to load a string from a file in your bundle
if let filepath = Bundle.main.path(forResource: "example", ofType: "txt") {
do {
let contents = try String(contentsOfFile: filepath)
print(contents)
} catch {
// contents could not be loaded
}
} else {
// example.txt not found!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment