The ‘uname’ utility is certainly useful for the result you’re after here.
But the ‘sysctl’ utility might also be useful for other and more detailed system information if needed.
For example these two “Terminal” give the same result.
uname -m
// And
sysctl -n hw.machine
But if you type this.
sysctl -a
You can get a full list of system information, which may not be what you’re after here, but might be useful for you at another time.
I can post a couple of Swift functions I created to use ‘sysctl’ in Swift projects if you’re interested.
I realise my reply was not specifically what you where asking here.
But just too offer an alternative to the ‘uname’ utility, just in case you might want other information, like say the processor type or name.
I haven’t touched Swift in a while, I wasn’t able to get it to run as is. This is what I tried. If you can adjust this so it runs, I can give it a go on an M1.
#!/usr/bin/env xcrun swift
private var getPlatform : String {
var systeminfo = utsname()
uname(&systeminfo)
let machine = withUnsafeBytes(of: &systeminfo.machine) {bufPtr->String in
let data = Data(bufPtr)
if let lastIndex = data.lastIndex(where: {$0 != 0}) {
return String(data: data[0...lastIndex], encoding: .isoLatin1)!
} else {
return String(data: data, encoding: .isoLatin1)!
}
}
return machine
}
print getPlatform()
Thanks… but I’ve discovered the that code will sometimes Lie to you (Rosetta) and tell you its Intel when it is not… but sysctl is supposed to give you the true platfom
I created a public struct as an extension for the ‘sysctl’ feature of the “Foundation” framework.
which has two static functions, one for string return data types, and one for Int64 return data types.
because the ‘sysctl’ utility can return either of these two data types, depending on the requested key.
This is a modified version of the function I use for string return values.
import Foundation
func sysctlNameString(for key: String) -> String {
if let keyString = key.cString(using: .utf8) {
var size: Int = 0
sysctlbyname(keyString, nil, &size, nil, 0)
var name = [CChar](repeating: 0, count: Int(size))
sysctlbyname(keyString, &name, &size, nil, 0)
return String(cString: name)
} else {
return "Error:"
}
}
and you would call it like this.
let hardwareArchitecture = self.sysctlNameString(for: "hw.machine")
The function for the numeric data types is slightly different, but you don’t need it for the system type.
For a list of the available ‘sysctl’ key’s you can use this in the “Terminal”.
Considering I’ve never seen you help ANYONE (even if it is a real beginner’s question) it is not too surprising that you can’t help Dave who is Pro level … so maybe don’t try bragging with your incompetence?
The letter K did not exist in the Latin alphabet originally, but was later borrowed from Greek, along with the letter Y, specifically to spell words that were borrowed from Greek. In other words K and Y were indicators of foreign words.
Usually the letter C was used for K and G sounds. My old latin teacher had a theory that I think is spot on:
The word Caesar developed into Kaiser in the West, and into Zar in the East.
Consequently Caesar would have originally be pronounced Ka-e-zar