Swift 中是否有 API 来确定 iOS 设备的处理器寄存器大小?

Is there an API in Swift to determine processor register size of iOS device?

我正在向用户显示他们的设备是 32 位还是 64 位。目前,我正在根据 UInt.max:

的值确定
let cpuRegisterSize = count(String(UInt.max, radix: 2))

感觉有点老套,所以我想知道 Swift 中是否有 API 而 returns 那个值。据我所知,UIDevice 似乎没有保存该信息。

在 32 位设备上 CGFloat 是浮点数。在 64 位设备上 CGFloat 是 Double。所以你可以使用 CGFLOAT_IS_DOUBLE 来检测当前架构。

let bit = 32 * (CGFLOAT_IS_DOUBLE + 1)

你也可以使用sizeof(Int):

let bit = sizeof(Int) == sizeof(Int64) ? 64 : 32
MemoryLayout<Int>.size == MemoryLayout<Int32>.size ? 32 : 64