5 ms·
> This is not something strings should do; I didn't mean that String should have a "pathExtension" property like NSString. I just want operations like "insert
by jakobegger 8y ago
> This is not something strings should do;
I didn't mean that String should have a "pathExtension" property like NSString. I just want operations like "insert a number before the last period" to be easier to do.
Also, there are a lot more things that are a pain with String. I mean, just the fact that I can't pass a Substring to a function that expects a String boggles my mind.
- saagarjha 8y agoYes, like I said, you should be using URL for this, which will make it possible to extract the filename without the extension, modify it, and get the path string from that (which is semantically what I believe you are trying to do). Not only does this create self-documenting code, it also makes it harder to fall into a the many “gotchas” that handling paths entails.
- jakobegger 8y agoYes, I know that, but I was just using filename manipulation as an example, because it was the first thing that came to my mind. I now see it was a bad example, since URL has a couple of APIs for file name handling. Anyway, these types of operations come up all the time when working with strings, and these operations are really really incovenient in Swift.
- saagarjha 8y ago> Anyway, these types of operations come up all the time when working with strings, and these operations are really really incovenient in Swift. Again, what are these operations? I think most of the issues people have with String is due to hard to discover APIs rather than design issues with String.
- jakobegger 8y agoText parsing is something that comes up often (for me). For example parsing CSV files, or parsing tab separated data from the clipboard, or parsing various types of config files. Swift has sweet solutions for a few special cases (eg. parse file names, parse dates, parse JSON), but parsing generic text is not something that Swift is good at. NSString has a rich set of APIs for those tasks (NSScanner, NSRegularExpression, and all the rangeOfString... methods). Swift has pretty much nothing. (There is firstIndex(of:), but as far as I can see there is no way to find the next index, which makes it pretty much useless for most parsing tasks) Maybe the problem is that I'm just not familiar enough with Swifts String, but until now every time I've had to work with Strings I became very frustrated.
- tinus_hn 8y agoI would strongly suggest that you don’t write a parser for .csv yourself, it’s a terrible format.
- a1369209993 8y ago> I just want operations like "insert a number before the last period" to be easier to do. Stuff.tar1.gz would like to have a word with you.