In a Mac app, how can I programmatically detect (at runtime) whether the app is currently running on a Mac with an Intel or Apple Silicon processor?
Solution compatible with Xcode 14 and newer.
We retrieve utsname.machine
and compare it to "arm64":
extension utsname {
static var sMachine: String {
var utsname = utsname()
uname(&utsname)
return withUnsafePointer(to: &utsname.machine) {
$0.withMemoryRebound(to: CChar.self, capacity: Int(_SYS_NAMELEN)) {
String(cString: $0)
}
}
}
static var isAppleSilicon: Bool {
sMachine == "arm64"
}
}
In Objective-C, you can use the system uname
function. This is equivalent to uname -m
from the shell.
#include <sys/utsname.h>
NSString *GetMachineHardwareName(void) {
struct utsname sysinfo;
int retVal = uname(&sysinfo);
if (EXIT_SUCCESS != retVal) return nil;
return [NSString stringWithUTF8String:sysinfo.machine];
}
or in Swift
func GetMachineHardwareName() -> String? {
var sysInfo = utsname()
let retVal = uname(&sysInfo)
guard retVal == EXIT_SUCCESS else { return nil }
return String(cString: &sysInfo.machine.0, encoding: .utf8)
}
For late-model Intel Macs, this returns x86_64
. For Apple Silicon, it returns arm64
.
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