Difference between revisions of "Code Snippet: Read File"
From Coder Merlin
(Created page with "== Read the contents of a file into a string == <syntaxhighlight lang="swift"> let contents = try! String(contentsOfFile: "hello.txt")...") |
|||
Line 1: | Line 1: | ||
== Read the contents of a file into a string == | == Read the contents of a file into a string == | ||
<syntaxhighlight lang="swift"> | <syntaxhighlight lang="swift"> | ||
import Foundation | |||
let contents = try! String(contentsOfFile: "hello.txt") | let contents = try! String(contentsOfFile: "hello.txt") | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 13:57, 6 December 2018
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Read the contents of a file into a string[edit]
import Foundation
let contents = try! String(contentsOfFile: "hello.txt")