Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically detect Apple Silicon vs Intel CPU in a Mac App at Runtime

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?

like image 759
Todd Ditchendorf Avatar asked Oct 17 '25 11:10

Todd Ditchendorf


2 Answers

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"
    }
}
  • "arm64" for Apple Silicon
  • "x86_64" or "i386" for Intel
like image 199
Cœur Avatar answered Oct 19 '25 23:10

Cœur


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.

like image 45
Todd Ditchendorf Avatar answered Oct 20 '25 00:10

Todd Ditchendorf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!