I'm beginning to wonder just how viable SwiftUI is for apps. Keep running into serious issues.
For example, I have several existing UIKit apps. All have the same exact about screen. I created a storyboard with the UI along with a view controller .swift file that can be added to all my projects via simple file reference.
In trying to do the same with SwiftUI, I created an AboutView.swift file that lives outside the project's folder hierarchy:
In my app project, I just dragged in the dependent AboutView.swift file.
Xcode (12.4) refuses to generate a preview though for AboutView. Giving me "Cannot preview in this file - active scheme does not build this file". That is false, when adding AboutView to the project, I included it in the app and UITest targets.
If I copy AboutView into the project (now just another local source file specific to that project), previews work again. I refuse to have twelve copies of these shared files; one per project!
I also tried folder references (e.g. dragging in that Common folder above). Same issue.
Tried a workspace that contained my app project and a simple project with my common views. Same issue.
Didn't even try local packages due to those failing miserably for me (separate thread on this forum with all those issues).
Side note: Building and running the app works great, it shows my about screen.
How is one supposed to be able to create a SwiftUI view and shared it across two or more projects? Why can't these be previewed? Each of my apps Assets.xcassets contains a Logo asset that is used in the about screen, so would be nice to see it in a preview and not have to rely on running the app in the simulator or on a device.
Finally, I'm thinking that Xcode can only generate previews of SwiftUI views in a project IFF their files are direct decendents on the project file's main folder on disk. Is that true? If so, why?
For example, I have several existing UIKit apps. All have the same exact about screen. I created a storyboard with the UI along with a view controller .swift file that can be added to all my projects via simple file reference.
In trying to do the same with SwiftUI, I created an AboutView.swift file that lives outside the project's folder hierarchy:
Code Block + Common + Views * AboutView.swift + MyApp * MyApp.xcodeproj + Views + (folder/file reference here for Common items) ...
In my app project, I just dragged in the dependent AboutView.swift file.
Xcode (12.4) refuses to generate a preview though for AboutView. Giving me "Cannot preview in this file - active scheme does not build this file". That is false, when adding AboutView to the project, I included it in the app and UITest targets.
If I copy AboutView into the project (now just another local source file specific to that project), previews work again. I refuse to have twelve copies of these shared files; one per project!
I also tried folder references (e.g. dragging in that Common folder above). Same issue.
Tried a workspace that contained my app project and a simple project with my common views. Same issue.
Didn't even try local packages due to those failing miserably for me (separate thread on this forum with all those issues).
Side note: Building and running the app works great, it shows my about screen.
How is one supposed to be able to create a SwiftUI view and shared it across two or more projects? Why can't these be previewed? Each of my apps Assets.xcassets contains a Logo asset that is used in the about screen, so would be nice to see it in a preview and not have to rely on running the app in the simulator or on a device.
Finally, I'm thinking that Xcode can only generate previews of SwiftUI views in a project IFF their files are direct decendents on the project file's main folder on disk. Is that true? If so, why?