Created
April 5, 2024 11:07
-
-
Save yannxou/1cae00676811a893cf8bab4c57fe6ab7 to your computer and use it in GitHub Desktop.
Swift: Detect code running in SwiftUI preview
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 ProcessInfo { | |
var isSwiftUIPreview: Bool { | |
environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" | |
} | |
// or: | |
static func isOnPreview() -> Bool { | |
return processInfo.processName == "XCPreviewAgent" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment