SwiftUI Previews for Watch Fail When Scheme Includes iOS App

I have a Watch companion app. The SwiftUI previews fail to build for the watch app. The errors indicate it is trying to build Swift package targets that are meant for iOS only, not the watch. The watch does not include these dependencies so it is perplexing it will try to build them.

Digging into the scheme for the watch app, it includes the iOS target as you can see the screenshot. This seems to be the default when you create a new watch target. If I uncheck the boxes for the iOS target, previews will build fine. But I think this means that each time I build my Watch target, it will not simultaneously build my iOS target. I'm not sure of the impact of that.

Is this a known limitation with Previews? Is there another workaround?

Replies

I had similar problem too. I guess you should select a watch simulator as a run destination in order to build the previews for watchOS. It started since Xcode 15.

  • See the screenshot of the error below. Is this what you mean by selecting the watch simulator as a run destination? The only way I can get previews to build is by removing the iOS target from the watch scheme in the description.

Add a Comment

Can you please file Feedback for this so we can investigate? Thank you. (Post the number here when you have it!)

A feedback case has been submitted FB13519259 including a demo project. Below is a screenshot of the error.

Any luck at all fighting this?

I submitted a very similar issue with a sample project as FB13566793. It's simply a case of creating a paired iOS and watchOS app and pulling in an SPM package to be used only by the iOS app. When it attempts to show a watchOS preview, for some reason it tries to pull the iOS-targeted package into the build for the watchOS preview. Very simple, very reproducible on other macs as well.

I've attempted workarounds but nothing has panned out. Anxious to hear if anyone has luck with this. It's still an issue in the Xcode 15.3 beta

I'm still using the workaround I mentioned in the description, which allows the previews to show for watch. I just remove the iOS app from the Watch target list in the scheme. The impact has been I need to explicitly switch targets to the iOS app when I need to build iOS. I'm not sure if you can submit to Apple this way but it has worked fine for debugging.