XCode Previews do not work when defined in a Swift Package in XCode 15 beta 6. The following error will be returned when trying to show a SwiftUI Preview:
FailedToInstallAppError: Failed to install ”XCPreviewAgent.app” Could not install the preview host ”XCPreviewAgent.app” on iPhone 14 Pro
...
HumanReadableNSError: Simulator device returned an error for the requested operation.
Ensure your bundle contains a valid CFBundleShortVersionString.
As far as I know, a Swift Package doesn't need a CFBundleShortVersionString declared? Am I missing something?
Replicate Error
To replicate the error, simply create a new SPM package from XCode, and create a Preview:
struct Preview: PreviewProvider {
static var previews: some View {
Group {
Text("Hello")
}
}
}
Does anyone know of any workaround this issue?
Hi,
Sorry to hear you are having problems getting previews working in your framework. What you are describing here sounds the same as what is listed here in the release notes:
Previewing a view inside of a Swift Package or framework fails. (113143384)
Workaround: If using a framework, embed the framework in an app in the active scheme. There is no workaround when using Swift Packages.