Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if client system is 32 or 64 bit?

Tags:

xcode

swift

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.

like image 804
udondan Avatar asked Dec 03 '22 18:12

udondan


2 Answers

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)
like image 187
rintaro Avatar answered Jan 06 '23 14:01

rintaro


swift 4 let is64bit = Int.bitWidth == Int64.bitWidth

like image 32
S-K' Avatar answered Jan 06 '23 16:01

S-K'