Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fbukevin
Created December 28, 2016 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbukevin/455a884f7f65c835d543ae62e859e745 to your computer and use it in GitHub Desktop.
Save fbukevin/455a884f7f65c835d543ae62e859e745 to your computer and use it in GitHub Desktop.
Load general text file in Swift 3
func loadText(file: String, handler: (String) -> Void){
if let path = Bundle.main.path(forResource: file, ofType: "txt") {
do {
let context = try String(contentsOfFile: path, encoding: .utf8)
handler(context)
} catch {
print(error.localizedDescription)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment