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?

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.

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.

Are there any updates?

xCode Version 15.4 the issue is this here.

So! this appears to be fixed in this week's Xcode 16 beta ... almost!

I can create a brand new project, add a package that the iOS app uses, and previews for the watchOS UI now show - finally!

HOWEVER! I cannot find a way to get my existing project to work. Removing the package in the Xcode 16 beta reliably crashes Xcode, so the only way to remove it is to drop back to 15, but the problem still persists in Xcode 16 - that I simply cannot get the watchOS previews to show.

At one point I did remove derived data, seemed not to help.

My project is old and large, so starting an Xcode project from scratch is a non-starter right now.

Anxious to hear about anyone else's experiences on this.

SwiftUI Previews for Watch Fail When Scheme Includes iOS App
 
 
Q