Cross-platform Swift Package to report the operating system name
and version
on which the app is running
Key Aspects:
UIDevice
vs. WKInterfaceDevice
vs. ProcessInfo
)import OSInfo
// Example for running on iPhone
print(OS.current.name) // "iOS"
print(OS.current.version) // OperatingSystemVersion(majorVersion:16, minorVersion:1,patchVersion:0)
print(OS.current.version.description) // "16.1"
print(OS.current.displayVersion) // "Version 16.1 (Build 20B72)"
// Example for running on iPad
print(OS.current.name) // "iPadOS"
print(OS.current.version.description) // "16.1"
print(OS.current.displayVersion) // "Version 16.1 (Build 20B72)"
print(OS.current.iOSFamily) // true
// Example for running on Apple Watch
print(OS.current.name) // "watchOS"
print(OS.current.version.description) // "9.1"
print(OS.current.displayVersion) // "Version 9.1 (Build 20S75)"
// Example for running on Apple Vision (natively)
print(OS.current.name) // "visionOS"
print(OS.current.version.description) // "1.0"
print(OS.current.displayVersion) // "Version 9.1 (Build 20S75)"
// Example for running on Apple Vision (natively)
print(OS.current.name) // "visionOS"
print(OS.current.version.description) // "1.0"
print(OS.current.displayVersion) // "Version 1.0 (Build 21N5165g)"
print(OS.current.iOSFamily) // true
// Example for running on Apple Vision (Designed with iPad) with SDK "iOS"
print(OS.current.name) // "iPadOS"
print(OS.current.version.description) // "1.0"
print(OS().version.description) // "17.0"
print(OS.current.displayVersion) // "Version 1.0 (Build 21N5165g)"
print(OS.current.iOSFamily) // true
// Example for running on Mac
print(OS.current.name) // "macOS"
print(OS.current.version.description) // "13.0.1"
print(OS.current.displayVersion) // "Version 1.0 (Build 21N5165g)"
print(OS.current.appleFamily) // true
// Example for running as Mac Catalyst (or unmodified iOS app) on Mac
print(OS.current.name) // "macOS"
print(OS.current.version.description) // "13.0.1"
// -- alternative
print(OS(underlyingMacOS: false).name) // "iPadOS"
print(OS(underlyingMacOS: false).version.description) // "16.1"
print(OS.current.displayVersion) // "Version 13.0.1 (Build 22A400)"
// Example for running on Linux
print(OS.current.name) // Linux
print(OS.current.version) // 5.15
print(OS.current.displayVersion) // Ubuntu 22.04.1 LTS
print(OS.current.appleFamily) // false
Note:
OS.current
is equivalent to OS(underlyingMacOS: true)
OS()
is equivalent to OS(underlyingMacOS: false)
link |
Stars: 25 |
Last commit: 4 weeks ago |
detect name
for visionOS correctly when using Xcode 15 Beta 6+
Needed because #if os(iOS)
behavior changed in Swift compiler
shipped in in Xcode 15 Beta 6
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics