Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module "MyApp" not found in UnitTest-Swift

Im trying to test some Swift class (@objc class) in my legacy Objc code. I am importing "UnitTests-Swift.h" in my test classes.

Then I get this error:

Module "MyApp" not found in the autogenerated "UnitTests-Swift.h"

This is whats inside the top part of the "UnitTests-Swift.h"

typedef int swift_int3  __attribute__((__ext_vector_type__(3)));
typedef int swift_int4  __attribute__((__ext_vector_type__(4)));
#if defined(__has_feature) && __has_feature(modules)
@import XCTest;
@import ObjectiveC;
@import MyApp;
@import CoreData;
#endif

I cleaned the project, checked all the relevant flags ("No such module" when using @testable in Xcode Unit tests, Can't use Swift classes inside Objective-C), removed derived data and so on.. No idea of whats happening, but I m quite sure that @import MyApp shouldnt be there..

Can anyone help me with this?

like image 546
Piga4 Avatar asked Nov 13 '15 08:11

Piga4


1 Answers

Just got this issue in my project and after the entire day spent on investigation I finally resolved it. Basically this happens because you have cyclic dependency between ObjC and Swift. So in my case it was:

  • Swift Protocol with @obj attribute in a main target;
  • Swift Class in UnitTest target which inherited this Protocol;
  • Import UnitTestTarget-Swift.h in any Objective-C class of your UnitTest target

So fairly simple combination leads to this error. In order to fix this you want either:

  • simply make sure that your Swift Class in UnitTest target is private, so it won't get to UnitTestTarget-Swift.h

or

  • do not mark your original Swift Protocol as @objc, which will allow you to access your SwiftClass from all ObjectiveC test classes, but those classes won't have any idea about the Swift Protocol.
like image 159
Oleg Kohtenko Avatar answered Oct 06 '22 09:10

Oleg Kohtenko