3 ms·
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", withExt
by melling 7y 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)
- dmitriid 7y agoThere's no chance in hell anyone learning Swift can figure these two lines out. 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?