Does someone know how to get the macOS Maschine na...
# multiplatform
s
Does someone know how to get the macOS Maschine name in macMain Multiplatform code? This is how it's done in Swift:
Copy code
import IOKit
import SwiftUI

func getModelIdentifier() -> String? {

  let service = IOServiceGetMatchingService(
    kIOMainPortDefault,
    IOServiceMatching("IOPlatformExpertDevice")
  )

  var modelIdentifier: String?

  if let modelData = IORegistryEntryCreateCFProperty(
    service,
    "model" as CFString,
    kCFAllocatorDefault,
    0
  ).takeRetainedValue() as? Data {

    modelIdentifier = String(
      data: modelData,
      encoding: .utf8
    )?.trimmingCharacters(in: .controlCharacters)
  }

  IOObjectRelease(service)

  return modelIdentifier
}
I struggle to translate the calls.
Same question for the iOS model name. utsname() doesn't exist.
Copy code
import SwiftUI

extension UIDevice {

  var modelName: String {

    var systemInfo = utsname()
    uname(&systemInfo)

    let machineMirror = Mirror(reflecting: systemInfo.machine)

    let identifier = machineMirror.children.reduce("") { identifier, element in
      guard let value = element.value as? Int8, value != 0 else {
        return identifier
      }
      return identifier + String(UnicodeScalar(UInt8(value)))
    }

    return identifier
  }
}