Hacker News new | ask | show | jobs
by dmitriid 2385 days ago
I couldn't figure it out on a Mac. Then I Googled it, and decided I'm better off solving this in languages I know (whatever I feel like today: JS, Python, Java, perhaps even Erlang) or in a language that has a reasonable standard library (Rust) than in this mess: https://twitter.com/dmitriid/status/1201441652507844608
1 comments

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)
There'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?