From d3fd23cfb3f0c5571cdb38b4b847341281e4d7b9 Mon Sep 17 00:00:00 2001 From: Brandon Williams <135203+mbrandonw@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:13:35 -0400 Subject: [PATCH] Print runtime warning in previews. (#135) * Print runtime warning in previews. * Use legacy previews --- Examples/Examples/ExamplesApp.swift | 7 +++++++ .../IssueReporters/RuntimeWarningReporter.swift | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/Examples/Examples/ExamplesApp.swift b/Examples/Examples/ExamplesApp.swift index 8467a29..ea6d03e 100644 --- a/Examples/Examples/ExamplesApp.swift +++ b/Examples/Examples/ExamplesApp.swift @@ -26,3 +26,10 @@ class ItemsModel { return lastItem } } + +struct Previews: PreviewProvider { + static var previews: some View { + 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: "/") })) )