Since I needed to detect this stuff for a project, I made a Swift package that includes your solutions and improves upon them and makes them easier to use.
It can also detect multiple architectures to have a more general usage.
https://github.com/ITzTravelInTime/SwiftCPUDetect
Here is some example usage of my package
import Foundation
import SwiftCPUDetect
print("Is my app running with Rosetta? \((AppExecutionMode.current() == .emulated) ? "Yes" : "No")")
print("My app is running using the \(CpuArchitecture.current()?.rawValue ?? "[Can't detect architecture]") architecture")
print("My computer is running using the \(CpuArchitecture.actualCurrent()?.rawValue ?? "[Can't detect architecture]") architecture")
Topic:
App & System Services
SubTopic:
General
Tags: