From a6a13c29bf72d875f09e853d9dbcd2455e24d8b5 Mon Sep 17 00:00:00 2001 From: winebarrel Date: Sun, 9 Aug 2026 18:10:48 +0900 Subject: [PATCH] Stop the preview app quitting on Xcode's launch arguments Running the MacstifyPreview scheme quit before the window appeared. Xcode launches the app with NSUserDefaults-style arguments - Document Versions is on by default in the Run action, which adds `-NSDocumentRevisionsDebugMode YES` - and the parser threw on the first argument it did not recognise. Single-dash flags and the value after them are now skipped. A misspelt `--option` still fails loudly, which is the case worth catching. Co-Authored-By: Claude Opus 5 (1M context) --- Preview/PreviewApp.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Preview/PreviewApp.swift b/Preview/PreviewApp.swift index 65a4199..3c80a99 100644 --- a/Preview/PreviewApp.swift +++ b/Preview/PreviewApp.swift @@ -219,6 +219,15 @@ private struct Options { let raw = try Self.value(after: argument, from: &iterator) try set(argument, to: raw, explicitSize: &explicitSize) default: + // Xcode launches the app with NSUserDefaults-style arguments + // such as `-NSDocumentRevisionsDebugMode YES`. Rejecting those + // means Run quits before the window ever appears, so skip any + // single-dash flag and the value that follows it. A misspelt + // `--option` still fails loudly. + guard argument.hasPrefix("--") else { + _ = iterator.next() + continue + } throw OptionError("unknown argument: \(argument)") } }