Skip to content

Instantly share code, notes, and snippets.

@KrisYu
Created March 18, 2016 01:27
Show Gist options
  • Save KrisYu/6bbd0c184c6a3754d46e to your computer and use it in GitHub Desktop.
Save KrisYu/6bbd0c184c6a3754d46e to your computer and use it in GitHub Desktop.
iOS reading txt file
func printData(){
guard let path = NSBundle.mainBundle().pathForResource("contacts", ofType: "txt") else {
print("Error while reading data")
return
}
do {
let content = try String(contentsOfFile: path, encoding: NSUTF8StringEncoding)
print(content)
// return content
} catch _ as NSError{
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment