Last active
December 25, 2023 22:27
-
-
Save davidsteppenbeck/b7601bd79db234af018b20d17b0689f2 to your computer and use it in GitHub Desktop.
A global function for providing multiplatform specific values in Swift.
This file contains hidden or 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
import Foundation | |
/// Returns the value for the current platform from the values that are provided. | |
/// | |
/// - Parameters: | |
/// - iOSValue: The value to use for the iOS platform. | |
/// - macOSValue: The value to use for the macOS platform. | |
func valueForPlatform<Value>(iOS iOSValue: @autoclosure () -> Value, macOS macOSValue: @autoclosure () -> Value) -> Value { | |
#if os(iOS) | |
iOSValue() | |
#elseif os(macOS) | |
macOSValue() | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment