12

I am trying build a Preview for a project that is built on SwiftUI. At first, I created the project with the name 'VOIP'. After some development and time, I connected it to the AppStore Connect and the name of the project was created differently, Let's say VoipApp. I can build the project into simulator or a device without any problem, however when I try to preview a SwiftUI View, it says No such module VOIP at project navigator. But as I said it just happens when I try to preview.

Here is the diagnostics;

no such module \'VOIP\'

----------------------------------------

SchemeBuildError: Failed to build the scheme "VOIP"

no such module 'VOIP'

Compile /Users/myuser/Projects/VOIP/VOIPTests/VOIPTests.swift:
/Users/myuser/Projects/VOIP/VOIPTests/VOIPTests.swift:10:18: error: no such module 'VOIP'
@testable import VOIP
             ^ 

I tried some answers from the network, but neither of them have been worked.

Faruk
  • 2,269
  • 31
  • 42
  • 1
    Do you have `VOIPTests.swift`? Is it really `import VOIP` there? Did you try to remove some of those, or both? Preview uses pre-built caches heavily - did you try to force clean everything, physically, like DerivedData, etc? – Asperi Mar 02 '20 at 17:33
  • Of course I do and there is. I did try to force clean but not the derived data. – Faruk Mar 02 '20 at 17:34
  • If it is there then why? Why don't remove it? You changed main app module name, so should rename it everywhere previous was used - it is not done automatically. – Asperi Mar 02 '20 at 17:39
  • I did not changed the module name, my employer created it with a different name on app store connect and when changed the team to get provisioning profiles it changed automatically. I mean my projects name still the same, which is `VOIP`, on my local. However I install it to simulator or a device the is as appearing as at the app store connect name. – Faruk Mar 02 '20 at 17:42
  • https://stackoverflow.com/a/26326618/1404324 this answer solved my issue. I just removed the scheme and created new one with new name. – Faruk Mar 02 '20 at 18:13

3 Answers3

38

The comment about recreating the scheme did not work for me. However, I found that I was able to change the module name to the value expected by SwiftUI by editing the "Product Module Name" setting:

enter image description here

Jeffrey Wear
  • 1,155
  • 2
  • 12
  • 24
  • 1
    This was the solution for me. I have 3 different schemas and build configurations, and the SwiftUI preview stopped working once added. Setting the "Product module name" as the project name solved the problem – Domenico Jan 31 '22 at 16:03
  • 2
    This didn't solved my issue. – Shrey Feb 16 '22 at 07:44
0

I just remove the pods and add my libraries through "Package Dependencies", it's show preview.

Raza Baloch
  • 334
  • 4
  • 9
-2

try "Xcode > Product > Clean Build Folder"。