In C, 'a'
, is a char
literal, equivalent to 97
. Swift has no such equivalent, requiring awkward spellings like ("a" as Unicode.Scalar).value
, which may or may not need additional casts to convert it to the right integer type. Or worse, spelling out the values in hex or decimal directly. This harms readability of code.
static char const hexcodes[16] =
{
'0', '1', '2', '3', '4' ,'5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'
};
let hexcodes:[UInt8] =
[48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102]
// what do these numbers mean???
i propose we use single quotes ('
) as an alternate spelling of integer literals, where the value is the unicode scalar value of the character. This is a logical and useful extension of the C model, in Swift we would now have 'ā' == 912
, and so we could use char literals for larger integer types as well.