How would one detect if a client system is 32 or 64 bit in Swift?
I wasn't able to find anything in documentation and I had a hard time finding a solution. Therefore posting the answer below.
The size of Int
is guaranteed to be the same as platform’s native word size. see the docs.
So this should works:
let bit = sizeof(Int) * Int(BYTE_SIZE)
let is64bit = sizeof(Int) == sizeof(Int64)
let is32bit = sizeof(Int) == sizeof(Int32)
swift 4
let is64bit = Int.bitWidth == Int64.bitWidth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With