Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-3381] Test-Swift.h tries to import app as module, fails #45969

Open
swift-ci opened this issue Dec 9, 2016 · 9 comments
Open

[SR-3381] Test-Swift.h tries to import app as module, fails #45969

swift-ci opened this issue Dec 9, 2016 · 9 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PrintAsClang Area → compiler: The PrintAsClang library

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Dec 9, 2016

Previous ID SR-3381
Radar rdar://problem/19245651
Original Reporter Catmull (JIRA User)
Type Bug

Attachment: Download

Environment

I'm using Xcode 8.1 with Swift 3.

I also found this issue reported a year ago on StackOverflow, tagged Swift 2 and Xcode 7, so it's not new.
http://stackoverflow.com/questions/33688767/module-myapp-not-found-in-unittest-swift

Additional Detail from JIRA
Votes 4
Component/s Compiler
Labels Bug, PrintAsObjC
Assignee None
Priority Medium

md5: a66a2afe2a9be2729702bd352c3e6556

Issue Description:

In my Xcode test target, the Test-Swift.h file includes the line "@import MyApp" which yields a "Module 'MyApp' not found" error.

@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Andria Jensen (JIRA)

I'm also seeing this same problem.

@bob-wilson
Copy link

Can one of you attach a sample project that demonstrates the problem?

@belkadan
Copy link
Contributor

belkadan commented Jun 1, 2017

It's pretty easy to set up: an application target with Swift in it, then a mixed-source unit test target where one of the .m files imports the generated header for the test target. One of the test source files should have an ObjC-compatible method that uses one of the app target's types.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Oct 3, 2017

Comment by Oleg Kokhtenko (JIRA)

@bob-wilson here you go a simple example. It has the same result in Xcode 8.3.3 and Xcode 9.0 as well.

Also, I believe that I described work around for this issue in this stackoverflow answer untill this issue is fixed.

ModuleImportIssue.zip

@swift-ci
Copy link
Collaborator Author

Comment by Andria Jensen (JIRA)

@bob-wilson We've just figured out a solution to this issue for our project. It's documented in the article here: https://medium.com/if-let-swift-programming/ios-tests-working-with-objective-c-and-swift-class-together-aaf40f91a27c

Specifically, the last part of the article. I added `$CONFIGURATION_TEMP_DIR/{ProjectName}.build/DerivedSources` to the `Header Search Paths` and now our Swift.h file is recognized and importing correctly for all of our unit tests. Hopefully this helps resolve this issue.

cc kohtenko (JIRA User)

@belkadan
Copy link
Contributor

That is a different problem, sorry. That only works if the Swift classes in the test target don't depend on Swift classes in your app target.

@belkadan
Copy link
Contributor

Something that might work: having PrintAsObjC call Context.getClangModuleLoader()->canImportModule(…) before recording an import. That'd handle overlays, mixed-source frameworks, and plain ObjC frameworks.

@swift-ci
Copy link
Collaborator Author

Comment by Aaron L'Heureux (JIRA)

Glad to see some activity on this - we're encountering this and it's a significant sore spot integrating new Swift code that we really want to write into existing Objective-C tests.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PrintAsClang Area → compiler: The PrintAsClang library
Projects
None yet
Development

No branches or pull requests

3 participants