XCode preview crashes when using resources accessed in another Swift Package

Context

  • I have a package shared by multiple projects. It contains localized strings. Localization works, as the tests, when run in French language, all pass.

Code Block swift
public struct MySubLibrary {
public static var helloWorld: String {
return NSLocalizedString("HELLO_WORLD", bundle: .module, comment: "Hello world sentence")
}
}

  • I have another package which contains SwiftUI Views, and which depends on the shared package. It also contains resources, such as images.

Code Block swift
Text(MySubLibrary.helloWorld)


Bug


When I use a localized string from the shared package, preview crashes.

The underlying error is:

Code Block text
Fatal error: unable to find bundle named MySubLibrary_MySubLibrary: file MySubLibrary/resource_bundle_accessor.swift, line 27


More details, diagnostics and screenshots


You can find example packages, along with the full details and diagnostics report in my xcode-preview-spm-resources-bug GitHub repository.

Accepted Reply

A workaround has been shared recently. I tested It and it works. I pushed it to a new "workaround" branch. I hope it will help 🤞🏻

Replies

A workaround has been shared recently. I tested It and it works. I pushed it to a new "workaround" branch. I hope it will help 🤞🏻