Here is a better explanation of the problem:
I am working on implementing SwiftUI. I want to take advantage of SwiftUI Preview on a project, but I am currently experiencing issues with getting access to app target resources.
Essentially I want to use app target schemes, and their bundled resources, to preview SwiftUI.
I have created a dummy project in order to test out my basic assumptions and verify my premise. The dummy project consists of two frameworks and three targets in the same project.
Two targets have the SwiftUI setup, the last one has a UIKit setup. One framework is the UI-framework, and there is another framework called Feature.
- App targets: SwiftUI-One, SwiftUI-Two, UIKit-One
- Frameworks: UI, Feature
The Feature framework contains the UI framework. This is to resemble the current setup in my project. App targets contains the Feature framework.
Each app target has an asset catalogue and a localization catalogue. The structure (naming) of these are the same, only the assets themselves are different.
With this setup I can create a View in the UI-module and reference images, colors and localizations, and use app target schemes to see how it looks for each target. This works 100% of the time, flawlessly.
When I recreate the same structure in my main project it does not work. However, there are some important differences in the test project and main project.
The test project has targets within the same Xcode project. In the main project there is a workspace containing different projects and targets.
Test project (Xcode project)
- SwiftUI-One (app target)
- SwiftUI-Two (app target)
- UIKit-One (app target)
- UI module (framework)
- Feature module (framework)
Main project (Xcode Workspace)
- App 1 project with app target
- App 2 project with app target
- UI project with framework target
- Feature project with framework target
The result of the structure of main project is that assets are not available to Preview by default, this is the practical difference from test project which is the goal.
I have also recreated the test project setup with the same structure (workspace + Xcode projects) to verify that is the problem.
When targets live in the same project I have access to asset resources based on target and scheme, but not when targets exist across projects.
My assumptions is how bundling works. Test project will show for example 'com.SwiftUI-One.dev' as the main bundle, and the main project will have a 'previews.com.apple.PreviewAgent.iOS' as main bundle.
Preview will still essentially work, but it will not retrieve any assets at all. When printing out all bundles I do not see the bundle for the app target itself, nor am I able to manually retrieve it using the bundle identifier.
I've also tried to use xcconfig-files combined with schemes, first to reference all assets in build phase and then to remove assets I don't want to add, but that just creates more work than it's worth.
There is no easy way to recreate the current main project to fit the functioning test project structure, so I am looking for alternative ways to solve this problem.