I apologize for yet another ObjC <-> Swift configuration woe, but I haven't found an existing question that describes my particular situation.
I have a mixed ObjC/Swift project with a mixed ObjC/Swift test suite. I'm able to access all of my main target classes, both Swift and ObjC, in all of my test suites, both Swift and ObjC.
So both of these test suites work currently:
#import "MainTarget-Swift.h"
@interface ObjCTestSuite: XCTestCase
@end
@implementation ObjCTestSuite
- (void)testSomething {
SwiftClass *thing = [SwiftClass new];
...
}
@testable import MainTarget
class SwiftTestSuite: XCTestCase {
func testSomething() {
let thing = ObjCClass()
...
}
}
The problem I'm running into is if I try to define a new Swift class in my test target and import the MainTargetTests-Swift.h
file into an ObjC test suite.
@objc class SwiftTestSupportClass: NSObject {
...
}
#import "MainTarget-Swift.h"
#import "MainTargetTests-Swift.h"
@interface ObjCTestSuite: XCTestCase
@end
@implementation ObjCTestSuite
- (void)testSomething {
SwiftClass *thing = [SwiftClass new];
SwiftTestSupportClass *helper = [SwiftTestSupportClass new];
...
}
This addition results in an error when I build my test target saying Module 'MainTarget' not found
and pointing to the line in MainTargetTests-Swift.h
where it has an @import MainTarget
line in the generated header.
// MainTargetTests-Swift.h
...
#endif
@import CoreGraphics;
@import Foundation;
@import ObjectiveC;
@import MainTarget;
...
@import UIKit;
#endif
...
I've tried all of the advice I've been able to extract from similar-but-not-the-same answers across SO and elsewhere.
- Clean Project, Delete Derived Data, Restart Xcode, pray, etc
- Make sure there are no import cycles in the project (Of course I can't be 100% certain of this, but I did a pass of being very diligent about only using forward declarations in all of my ObjC code)
- Make sure there are no other errors in the project. The whole suite builds and runs successfully until I simply add that import line to an ObjC file, not even trying to access a Swift class.
- Make
$(SRCROOT)
framework search path recursive on the test target to try to find the MainTarget module.
The MainTargetTests-Swift.h
appears identical whether I import it or not, so the @import MainTarget
line seems to be valid/benign until I try to include it in a .m
file, at which point it can't be found. This feels like some kind of header retain cycle to me given that piece of information, but I don't know of any way to verify that hypothesis or ensure that I don't have an import cycle in my main target or test target.
I'm able to accomplish this setup in a blank ObjC project, adding Swift files to the main target and the test target and referencing them through the corresponding bridging headers and generated MainTarget-Swift.h
and MainTargetTests-Swift.h
. The first difference I see in this setup is that the @import MainTarget
line does not appear in the test target's Swift header, so that could be a clue - I don't know why the main target is added as an import to the test target in my project. It's a CocoaPods project (of course), but I don't see anywhere I'm listing the main target as a framework dependency of the test target, so that's another unknown.
That's about all the information I can think of that's relevant at the moment, please leave a comment if I can clarify anything else about my setup or if you have hypotheses to test or have ways to gather more information about this situation. Thanks, as always, in advance.
Aucun commentaire:
Enregistrer un commentaire