[Experiment] Debugging Reducers in SwiftUI Previews #1234
tgrapperon
started this conversation in
Ideas
Replies: 1 comment
-
I've added some button to toggle the console's visibility and a Since this is a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
While working on hyper-modularized projects, it can be sometimes inconvenient to spin an app to inspect things a little closer (even dedicated feature apps). I'm aware that you can hook the debugger onto the Previews' process, but this is also quite inconvenient to do.
These helpers allow to print the result of
.debug()
reducers to live SwiftUI Previews (which are the default mode starting from Xcode 14). You only need to use.debugUI()
instead of.debug()
on the reducers you want to inspect, and use the.debugUI()
view modifier in your previews. This.debugUI
modifier optionally allows to specify an alignment (.top
or.bottom
for example) as well as aheight
or the font size for the virtual console. It displays it as a static overlay on top of its view.I made the feature so it can run on iOS 13, with the smallest footprint possible. It is self-contained in a 200 lines single file that you can use in your projects, whatever branch of TCA you're using right now.
It is obvious that SwiftUI could allow even more than simple logs, especially with protocol reducers, but I feel that this already helps a lot.
What do you think about it?
Beta Was this translation helpful? Give feedback.
All reactions