Created
March 7, 2024 17:46
-
-
Save VaslD/c962f3f1836ac961e14067b50db07b55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIDevice { | |
func systemVersion() -> String { | |
let os = switch self.userInterfaceIdiom { | |
case .pad: "iPadOS" | |
case .mac: "Mac Catalyst" | |
case .tv: "tvOS" | |
case .vision: "visionOS" | |
default: "iOS" | |
} | |
let version = "\(os) \(self.systemVersion)" | |
var name = [CTL_KERN, KERN_OSVERSION] | |
var length = 0 | |
guard sysctl(&name, 2, nil, &length, nil, 0) == 0, length > 0 else { return version } | |
var build = [CChar](repeating: 0x00, count: length) | |
guard sysctl(&name, 2, &build, &length, nil, 0) == 0, length > 0 else { return version } | |
return "\(version) (\(String(cString: build)))" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment