For the case that I described above (using image resources in SwiftUI preview inside SPM library targets), I am using a workaround that technically works, but it's silly and backwards. I embed the image resources in code as Base64.
import Foundation #if DEBUG let image_base64 = "… image as base64 …" let image_data = Data(base64Encoded: image_base64)! #endif
You can then use the data constant in SwiftUI previews to create images or do anything else. Just similarly need to gate the previews with
This is technically fine, but it is of course awkward to encode and embed the resource like this. It's OK if the resource does not change often.
To add insult to injury, Xcode is not able to render text files with very long lines. Here is what it looks like in Xcode. The minimap is correct, but the content area is blank for this single very long line. So you need to use an external text editor to edit this.