I have some SwiftUI code and it seems to work great when I build to a real iOS device or to an iOS simulator.
However in the SwiftUI canvas the preview says Failed
Finally figured it out!
So it turns out, the reason it couldn't find the library was because I was referencing it with a relative path to a spot outside of my project directory.
My build settings had the Framework Search Paths
set up like this:
../path/to/my/framework
And when I normally built my project this worked fine and it would find the framework. So it seems as though by default my build script is run from my project directory.
When I tried to build for SwiftUI, it must have been doing so from outside my root project directory so the relative framework path so no longer correct and I got the error shown in the question.
Updating the framework search path to a (slightly less relative?) path like this:
$(PROJECT_DIR)/../path/to/my/framework
made it so the framework could be found. Now I can successfully build the project and my SwiftUI canvas updates as it should.
So I had this same issue except it couldn't find my own module... For me the problem was because I have custom build configurations and it didn't like the custom module name. The solution was to rename the module to the same as debug and release in Build Settings > Product Module Name
I hope this helps someone