How to get the current OS name and version in Swift

1 Answer

0 votes
import Foundation

let processInfo = ProcessInfo.processInfo

// Get detailed OS version information
let osVersion = processInfo.operatingSystemVersion

print("Operating System: macOS/iOS")
print("Major Version: \(osVersion.majorVersion)")
print("Minor Version: \(osVersion.minorVersion)")
print("Patch Version: \(osVersion.patchVersion)")

 
 
/*
run:

Operating System: macOS/iOS
Major Version: 5
Minor Version: 15
Patch Version: 0
 
*/

 



answered Mar 28, 2025 by avibootz

Related questions

1 answer 100 views
1 answer 102 views
1 answer 105 views
1 answer 111 views
1 answer 74 views
1 answer 94 views
3 answers 109 views
...