|
|
|
|
|
by melling
2386 days ago
|
|
Last night I gave the complete solution in Swift below. Here are the two lines to read the file: let path = Bundle.main.url(forResource: "input01", withExtension: "txt")
var text = try String(contentsOf: path!, encoding: .utf8)
|
|
Besides, there are immediate additional questions:
- what's a bundle, and why does a Bundle deal with urls?
- What's the difference between Bundle.main.url and FileManager.main.urls, and why one and not the other?
- where does the resource come from?
- how do I read a file from a path?
- Why is String responsible for reading (and writing!) contents of a file? In which world is this good design?