4

I'm incorporating SwiftUI into my project for the very first time!

Unfortunately I can't preview my first SwiftUI file I add to the project. The build only fails on the preview. And the failure is in my tests.

Steps to build error:

  1. Click the "resume" button in the preview area for a newly created SwiftUI view.
  2. Build fails... I click the 'Diagnostics' button:

Diagnostics screen output:

missing required module 'JGProgressHUD'


SchemeBuildError: Failed to build the scheme "MyApp"

missing required module 'JGProgressHUD'

Compile AppTests.swift (x86_64): /Users/myname/Projects/MyApp/MyAppTests/Entities/AppTests.swift:11:8: error: missing required module 'JGProgressHUD' import MyApp ^

Yes, I have the JGProgressHUD lib imported via SPM.

This is what my test class looks like - it is failing on the import of "MyApp", but only for the preview of SwiftUI... there are no build failures for the app or tests otherwise...

import Foundation
import XCTest
import MyApp
// import app here because of: https://stackoverflow.com/questions/27172481/swift-singleton-init-called-twice-in-xctest

class AppTests: XCTestCase {
 // .. tests are here
}

Fails on the "Import MyApp" line.

Here's what I've tried:

  • searching everywhere online
  • messing with build schemes
  • made an example project with JGProgressHUD and tests, no issues with previewing
  • Verified that none of my swift files were added to the test target - none of them are, only xib files.
  • added "import JGProgressHUD" to the test file, then the preview build fails on this import line for JGProgressHUD.

I can't wait to use SwiftUI, but it seems pretty fickle so far adding to a new project, and I have no idea where else to look. Its such a random problem for what I'm trying to do, I am completely out of ideas for where to look.

Any ideas on what to check or look for?

Thanks for any help XCode sages!

18
  • Try @testable import MyApp Commented Mar 11, 2021 at 23:33
  • Thanks for the suggestion, but still has error -- "error: missing required module 'JGProgressHUD' @testable import MyApp ^" Commented Mar 12, 2021 at 0:41
  • The you will need to add that module to your test target as well Commented Mar 12, 2021 at 0:42
  • Its a swift package (SPM) which I assume applies to all targets as they seem to be global to the workspace when your test target has the host application set to the main application. Is it possible to exclude/include swift packages a test target of this type? Under MyAppTests Target -> General, it shows "Host Application: MyApp" with "Allow testing host application APIs" checked. There are no other options under "General" there for the test target. Commented Mar 12, 2021 at 0:49
  • 1
    My Feedback ID is FB9096575. Commented May 4, 2021 at 15:08

1 Answer 1

1

Apple fixed this in XCode 13 Beta 5.

Please verify and post here if Apple's fix has resolved your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.