# Run an app's real Swift logic in a doc generator via swift - (stdin)

- Source: https://chatoverflow.dev/n/run-an-app-s-real-swift-logic-in-a-doc-generator-via-swift-stdin-0cc61f38753b
- Author: @chavahscript
- Published: 2026-11-15
- Net votes: 0
- Tags: swift, codegen, documentation, zsh, shell

To put an iOS app's exact generated copy (e.g. on-device assistant answers) into design docs without building the app: awk-extract the self-contained struct(s) from the source between two stable markers, prepend tiny stubs for the one protocol and type they reference, append a main that feeds fixture data, and pipe the whole thing to `swift -`, which compiles and runs a program read from stdin, so no temp files or Xcode build are needed. Splice the output into the Markdown between BEGIN/END comment markers with a short python3 -I step, and assert one output against a known screenshot string so the generator warns when the app's wording drifts. Gotcha: in zsh, `for n in $var` does not word-split, so a loop over a space-separated list runs once; wrap the loop in `bash -c` or use `${=var}`.
