@@ -30,7 +30,7 @@ And following:
3030``` swift
3131let package = Package (
3232 dependencies : [
33- .package (url : " https://github.com/YusukeHosonuma/SwiftUI-Simulator.git" , from : " 1.3 .0" ),
33+ .package (url : " https://github.com/YusukeHosonuma/SwiftUI-Simulator.git" , from : " 1.4 .0" ),
3434 ],
3535 targets : [
3636 .target (name : " <your-target-name>" , dependencies : [
@@ -43,15 +43,21 @@ let package = Package(
43432 . Surround the your app's root view with ` SimulatorView ` .
4444
4545``` swift
46+ #if DEBUG
4647import SwiftUISimulator
48+ #endif
4749
4850@main
4951struct ExampleApp : App {
5052 var body: some Scene {
5153 WindowGroup {
54+ #if DEBUG
5255 SimulatorView { // ✅ Please surround the your app's root view with `SimulatorView`.
5356 ContentView ()
5457 }
58+ #else
59+ ContentView ()
60+ #endif
5561 }
5662 }
5763}
@@ -75,6 +81,113 @@ struct ExampleApp: App {
7581 - For example, it may not work if you have resolve ` locale ` by yourself. (e.g. use [ SwiftGen] ( https://github.com/SwiftGen/SwiftGen ) )
7682- ` sheet() ` and ` fullScreenCover() ` are not working currently. [ #37 ] ( https://github.com/YusukeHosonuma/SwiftUI-Simulator/issues/37 )
7783
84+ ## Custom Debug Menu
85+
86+ You can add custom debug menu.
87+
88+ ``` swift
89+ SimulatorView {
90+ // 💡 Add custom debug menu.
91+ Button {
92+ print (" Hello!" )
93+ } label : {
94+ Label (" Custom Debug" , systemImage : " ant.circle" )
95+ }
96+ } content : {
97+ ContentView ()
98+ }
99+ ```
100+
101+ This makes it easy to run custom debug action.
102+
103+ <img width =" 267 " alt =" image " src =" https://user-images.githubusercontent.com/2990285/165664233-758912e1-2aa3-4028-b1a0-43182329d02f.png " >
104+
105+ ## Built-in Modifier (Experimental)
106+
107+ As a built-in, we provide a modifier that displays the file name of the View.
108+
109+ | Debug enabled | Debug disabled |
110+ | -- | -- |
111+ | <img width =" 300 " alt =" image " src =" https://user-images.githubusercontent.com/2990285/165674830-b4167811-162c-4d9b-985c-eb8a22ff83e5.png " > | <img width =" 300 " alt =" image " src =" https://user-images.githubusercontent.com/2990285/165674861-1b473561-c164-4d5e-8bb1-8a7bf77780a1.png " > |
112+
113+ The installation procedure is as follows. (recommended)
114+
115+ 1 . Add ` View+Debug.swift ` .
116+
117+ ``` swift
118+ import SwiftUI
119+
120+ #if DEBUG
121+ import SwiftUISimulator
122+ #endif
123+
124+ public extension View {
125+ func debugFilename (_ file : StaticString = #file ) -> some View {
126+ // ✅ Enabled when debug build only.
127+ #if DEBUG
128+ simulatorDebugFilename (file) // 💡 or any `String`.
129+ #else
130+ self
131+ #endif
132+ }
133+ }
134+ ```
135+
136+ 2 . Add custom debug menu and environment.
137+
138+ ``` swift
139+ struct ExampleApp : App {
140+ //
141+ // ✅ To show/hide
142+ //
143+ #if DEBUG
144+ @State private var isEnabledDebugFilename = false
145+ #endif
146+
147+ var body: some Scene {
148+ WindowGroup {
149+ #if DEBUG
150+ SimulatorView {
151+ //
152+ // ✅ Add debug menu.
153+ //
154+ Menu {
155+ Toggle (isOn : $isEnabledDebugFilename) {
156+ Label (" Filename" , systemImage : " doc.text.magnifyingglass" )
157+ }
158+ } label : {
159+ Label (" Debug" , systemImage : " ant.circle" )
160+ }
161+ } content : {
162+ RootView ()
163+ //
164+ // ✅ Add `simulatorDebugFilename` environment value to root view.
165+ //
166+ .environment (\.simulatorDebugFilename , isEnabledDebugFilename)
167+ }
168+ #else
169+ ContentView ()
170+ #endif
171+ }
172+ }
173+ }
174+ ```
175+
176+ 3 . Add ` debugFilename() ` modifier to any views. (where you needed)
177+
178+ ``` swift
179+ struct FooView : View {
180+ var body: some View {
181+ Text (" Foo" )
182+ .debugFilename () // ✅
183+ }
184+ }
185+ ```
186+
187+ Note:
188+ As you can probably imagine, it is easy to make this yourself.
189+ Please refer to [ DebugFilenameModifier.swift)] ( https://github.com/YusukeHosonuma/SwiftUI-Simulator/blob/main/Sources/SwiftUISimulator/DebugFilenameModifier.swift ) .
190+
78191## Configurations
79192
80193You can specify default ` devices ` , ` locale identifiers ` , ` calendar identifiers ` and ` timezone ` .
0 commit comments