DavidPeicho / unity-swiftui-example

Integration example of the Unity engine in a SwiftUI-based application
MIT License
70 stars 15 forks source link

Does this example work with XCode Preview? #8

Closed Artein closed 2 years ago

Artein commented 2 years ago

One of the greatest features of SwiftUI is to receive almost immediate response to changes via XCode Preview. Does the combination of Unity with SwiftUI work in XCode Preview?

DavidPeicho commented 2 years ago

No it doesn't. However, a good way to still be able to debug your app especially the UI is to conditionally compile the Unity code with macros: #if.

I basically do that for the simulator. In the simulator, the Unity code is stripped away and mocked up to return dummy data. Developers can still debug the UI.

Artein commented 2 years ago

Thank you, @DavidPeicho . Please, let me know if you will find the way. For fine-tuning of UI, it is a great feature.

For now, I found an additional workaround (without #if's and so on), to just compile to my Mac as an app designed for iPhone. Everything works as expected and super fast (at least on my MacBook Pro 2021 with M1 Pro)

Screenshot 2022-02-04 at 10 16 25
DavidPeicho commented 2 years ago

Yes that's a good idea!

TBH I didn't try to work on that because:

If really I need to see the entire app running together, I run it on phone. We have a large app (500mB) and building on iPhoneX takes 2-3s on Macbook Pro 16 (obviously when re-building, not for an initial cold build).