Hacker News new | past | comments | ask | show | jobs | submit login

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



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?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: