From f508c04ecdb3e753dee670b915bcadfb7b7a5c7a Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 26 Sep 2024 09:40:13 -0400 Subject: [PATCH] Print runtime warning in previews. --- Examples/Examples/ExamplesApp.swift | 5 +++++ .../IssueReporters/RuntimeWarningReporter.swift | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Examples/Examples/ExamplesApp.swift b/Examples/Examples/ExamplesApp.swift index 8467a29..9a369e8 100644 --- a/Examples/Examples/ExamplesApp.swift +++ b/Examples/Examples/ExamplesApp.swift @@ -26,3 +26,8 @@ class ItemsModel { return lastItem } } + +#Preview { + let model = ItemsModel() + Text(model.lastItem?.description ?? "No last item") +} diff --git a/Sources/IssueReporting/IssueReporters/RuntimeWarningReporter.swift b/Sources/IssueReporting/IssueReporters/RuntimeWarningReporter.swift index 9d95dda..e13aa2a 100644 --- a/Sources/IssueReporting/IssueReporters/RuntimeWarningReporter.swift +++ b/Sources/IssueReporting/IssueReporters/RuntimeWarningReporter.swift @@ -66,6 +66,11 @@ public struct _RuntimeWarningReporter: IssueReporter { column: UInt ) { #if canImport(os) + guard ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] != "1" + else { + print("🟣 \(fileID):\(line): \(message() ?? "")") + return + } let moduleName = String( Substring("\(fileID)".utf8.prefix(while: { $0 != UTF8.CodeUnit(ascii: "/") })) )