markbattistella/platformchecker
PlatformChecker provides a structured and intuitive way to access environment-specific checks across different Apple platforms. It is designed to facilitate the integration of platform-specific functionalities in cross-platform Swift projects.
Features
- Platform Checks: Quickly determine which Apple platform your application is currently running on (iOS, macOS, watchOS, tvOS, visionOS).
- Device Checks: Easily identify device types such as iPhone, iPad, and Vision devices.
- Environment Checks: Check if your app is running as a Mac Catalyst app, in a simulator, or through TestFlight, and whether it's in debug mode.
- Version and Design Checks: Detect OS 26+ availability and Liquid Glass opt-out status.
Requirements
- Swift 6.0+
- iOS 12+, macOS 10.13+, Mac Catalyst 13+, tvOS 12+, watchOS 4+, visionOS 1+
Installation
Swift Package Manager
You can add PlatformChecker to your project via Swift Package Manager. Add the following dependency to your Package.swift:
dependencies: [
.package(
url: "https://github.com/markbattistella/PlatformChecker.git",
from: "26.2.21"
)
]Usage
Import PlatformChecker in the Swift file where you want to use the platform and device checks:
import PlatformCheckerExample Usage
Here are some examples of how you can use PlatformChecker in your project:
if Platform.isiOS {
print("Running on iOS")
}
if Platform.isiPhone {
print("Device is an iPhone")
}
if Platform.isDebugMode {
print("Debug mode is enabled")
}These checks can be used to conditionally apply logic or configurations based on the operating system, device type, or runtime environment.
Device idiom checks that read UIKit's UIDevice.current.userInterfaceIdiom are main-actor isolated under Swift 6.
Properties
| Property | Description | |--------------------|---------------------------------------------------------------------------| | Platform.isiOS | Returns true if running on iOS, excluding Mac Catalyst apps. | | Platform.isTVOS | Returns true if running on tvOS. | | Platform.isMacOS | Returns true if running on macOS, excluding Mac Catalyst apps. | | Platform.isWatchOS| Returns true if running on watchOS. | | Platform.isVisionOS| Returns true if running on visionOS, specific to Apple's Vision Pro devices. | | Platform.isiPhone| Returns true if the device is an iPhone, excluding Mac Catalyst. | | Platform.isiPad | Returns true if the device is an iPad, excluding Mac Catalyst. | | Platform.isTV | Returns true if the device is identified as a TV. | | Platform.isVisionDevice| Returns true if the device is a Vision device, specific to visionOS. | | Platform.isMacCatalyst| Returns true if the app is running as a Mac Catalyst app. | | Platform.isSimulator| Returns true if the app is running in a simulator. | | Platform.isDebugMode| Returns true if the current build configuration is set for debugging. | | Platform.isTestFlight| Returns true if the app is running through TestFlight. | | Platform.isiOS26OrNewer| Returns true if the current OS is version 26.0 or newer. | | Platform.isBeforeiOS26| Returns true if the current OS is earlier than version 26.0. | | Platform.liquidGlassStatus| Returns .enabled, .optedOut, or .unavailable. | | Platform.isUsingLiquidGlass| Returns true when Liquid Glass is available and not opted out. | | Platform.hasOptedOutOfLiquidGlass| Returns true when the app opted out of Liquid Glass. | | Platform.isLiquidGlassUnavailable| Returns true when the current OS does not support Liquid Glass. |
Documentation
Each property in the Platform struct is documented with inline comments that explain what the property checks and its intended use case.
Contributing
Contributions are welcome! If you have suggestions or improvements, please fork the repository and submit a pull request.
License
PlatformChecker is released under the MIT license. See LICENCE for details.
Package Metadata
Repository: markbattistella/platformchecker
Default branch: main
README: README.md