This alone is grounds for opening and drinking very expensive champagne and/or wine.
This alone is grounds for opening and drinking very expensive champagne and/or wine.
Can I finally extract a substring from the middle of a string using integer offsets, in one line? Something like string.utf8.substr(3, 5)?
Or does it still take an absolutely insane and unacceptable 4 lines of code with throwaway temp variables to track the start and end indexes? The inability to do basic string manipulations is a major turnoff, to the point it makes the entire language look like a bad joke.
String(s.dropFirst(3).prefix(5))The existing solution to this problem already uses integers (the offsetBy arguments)! I'm not talking about refactoring the String type, or breaking backwards compatibility. There would be no change in how the underlying String storage or access works. It's about adding a level of (zero overhead!) abstraction to simplify a common, basic operation.
Every other language I've ever touched has easy to use substrings. It makes absolutely no sense that Swift requires assigning throwaway constants to represent the start and end indexes for a simple substring extraction. There's this level of superiority regarding the purity and correctness of Swift's String type that clouds developers' ability to see that there is no limitation to doing this. It blows my mind that the most modern major language is this clunky.
wine.insert("Champagne")
But yes, in Swift, arrays, dictionaries, sets and strings are all mutable. They are also value types, so mutation is a purely local effect.
let array = [1, 2, 3] var mutableArray = [4, 5, 6] var anotherMutable = array
Not sure how much optimisation is done under the hood, but Swift compiler loves to complain about mutable structures that are not ever edited.
enum Booze: String {
case wine,
case champagne,
case beer,
case whiskey
}
let wine = [Booze.champagne]
</ocd> enum Booze {
case Wine(region: String)
case Beer
case Whiskey
}
let drink = Booze.Wine(region: "Champagne")
Now.. Anyone want to demonstrate how to use enums for the wine region or, say, whiskey subtypes? Should we use classes?