5

I have 3 different configurations for my project (Local, Dev, Release) and I can't get SwiftUI preview to work.

Compiling failed: no such module 'MyProject'...
Objects-normal/x86_64/MyView.2.preview-thunk.swift:1:64: error: no such module 'MyProject'
@_private(sourceFile: "MyView") import MyProject

As far as I understood, problem is with module name where preview canvas is trying to resolve main release name 'MyProject', but in debug it should be MyProject_Local (at least that value is set under Build Settings => Packaging => Product Module Name).

I would probably be able to hack this by setting my Debug product module name to "MyProject", but I was wondering if I can force preview canvas to somehow use correct configuration?

zhuber
  • 5,364
  • 3
  • 30
  • 63
  • I've got the exact same problem. Did you ever solve this? – Tometoyou Aug 26 '21 at 17:05
  • @Tometoyou No, I'm still using "hack" by having "MyProject" module name for Debug configuration. – zhuber Aug 27 '21 at 06:48
  • 1
    okay thank for the update. I talked to some others and they think it could be an Xcode bug, since building correctly selects the right module. Have you tried the Xcode 13 beta builds? Apparently some of the bugs have been fixed but not sure if this one has been! – Tometoyou Aug 27 '21 at 09:17
  • Not yet, I'm currently working on some backend code so I haven't used Xcode for few weeks now, but will definitely try when I get some time. – zhuber Aug 27 '21 at 10:32
  • Just downloaded Xcode 13.1 RC and I'm getting the same issue as @zhuber . Did anyone happen to resolve this issue with running SwiftUI previews. – alenm Oct 20 '21 at 14:50
  • 2
    I'm on Xcode 13.2.1 and this is still an issue. Glad I found this post as it confirms my suspicions of Xcode not appending the right module name per config. – Atticus Mar 15 '22 at 02:50
  • Incredible that this issue hasn't been fixed with Xcode 13.4.1. Still stuck with the same issue – Alexandre Nussbaumer Jul 29 '22 at 09:38
  • Experiencing the same issue. Sorry if this question is unqualified but why can't the schemas just share Product Module Name like the "hack" suggest? It works for me as well and doesn't seem to mess up any other schema-based configurations in my app. – Ferenziz Oct 31 '22 at 18:53

0 Answers0