SwiftUI Previews Not Working In Swift Packages (XCode 15 beta 6)

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?

Answered by Developer Tools Engineer in 762007022

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.

Accepted Answer

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.

I’m seeing the same “FailedToInstallAppError: Failed to install ”XCPreviewAgent.app” Could not install the preview host ”XCPreviewAgent.app” on iPhone 14 Pro” issue (with the same beta build of Xcode 15). In my case, I have a PreviewProvider declared in a file in a framework that is embedded in an app target. The current scheme is configured to launch the app.

😐 Frustrated. SwiftUI Previews have never worked smoothly.

Beta 4 worked great ( beta 5 ok I guess but the file bug was too much for me ), the best experience of previews I ever have had

hoping that beta 7 makes it better. Always afraid they will go Final on one of builds with these egregious bugs.

This issue was resolved for me with Xcode 15 beta 7. However, I now have another error when trying to build Previews. See this issue https://developer.apple.com/forums/thread/736152#736152021

SwiftUI Previews Not Working In Swift Packages (XCode 15 beta 6)
 
 
Q