In our code, we found a bug from not writing the alphabet correctly. Instead of "0123456789abcdefghijklmnopqrstuvwxyz"
, we had "0123456789abcdefghijklmnoqprstuvwxyz"
. So we are wondering if it's possible to avoid similar typo by declaring Strings made from ranges of characters?
Using Swift 4.1+, we tried:
attempt 1
let 1: String = "0"..."9" + "a"..."z"
Adjacent operators are in non-associative precedence group 'RangeFormationPrecedence'
attempt 2
let 2: String = ("0"..."9") + ("a"..."z")
Binary operator '+' cannot be applied to two '
ClosedRange<String>
' operands
attempt 3
let 3: String = String("0"..."9") + String("a"..."z")
Cannot invoke initializer for type 'String' with an argument list of type '
(ClosedRange<String>)
'
attempt 4
let 4: String = (Character("0")...Character("9")) + (Character("a")...Character("z"))
Binary operator '+' cannot be applied to two '
ClosedRange<Character>
' operands
attempt 5
let 5: String = String(Character("0")...Character("9")) + String(Character("a")...Character("z"))
Cannot invoke initializer for type 'String' with an argument list of type '
(ClosedRange<Character>)
'