简体   繁体   English

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

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

I am displaying to the user whether their device is 32-bit or 64-bit. 我向用户显示他们的设备是32位还是64位。 Currently, I am determining that based on the value of UInt.max: 目前,我正在根据UInt.max的值确定这一点:

let cpuRegisterSize = count(String(UInt.max, radix: 2))

It feels a little hacky, so I was wondering if there was an API in Swift that returns that value instead. 感觉有点骇人听闻,所以我想知道Swift中是否有API会返回该值。 UIDevice doesn't seem to hold that information, from what I can tell. 据我所知,UIDevice似乎不保存该信息。

On 32-bit devices CGFloat is Float. 在32位设备上, CGFloat为Float。 On 64-bit devices CGFloat is Double. 在64位设备上, CGFloat为Double。 So you can use CGFLOAT_IS_DOUBLE to detect current architecture. 因此,您可以使用CGFLOAT_IS_DOUBLE来检测当前架构。

let bit = 32 * (CGFLOAT_IS_DOUBLE + 1)

You can also use sizeof(Int) : 您还可以使用sizeof(Int)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM