In C++, I can write 123457890ull
to imply it's an unsigned long long integer. Does Swift provide similar language construct?
auto n = 12345ull;
Well, n
is unsigned long long
, which isn’t necessarily uint64_t
in C-based languages (-:
Real world example (unit test)
That’s a bit tricky because you rely on the tuple labels. I’d probably give the array a type:
let tests: [(s: _, v: UInt64)] = [
("1234", 1234),
("1kb", 1024),
("1234k", 1234 * 1024),
("3mb", 3 * 1024 * 1024),
("2GB", 2 * 1024 * 1024 * 1024),
("7tb", 7 * 1024 * 1024 * 1024 * 1024),
]
Note that I’m using _
as a type placeholder for s
(per SE-0315). I’m also relying on Swift’s built-in conversion from unlabelled to labelled tuples. This yields a value with the right type with a reasonably small amount of ceremony.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"