Created
October 23, 2020 14:57
-
-
Save tkausch/29fa0bf14589b36244833861267bf70c to your computer and use it in GitHub Desktop.
How to load a string from a file in your bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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