How should a Swift + Objective-C project be setup

2019-01-17 03:04发布

I'm finding it very hard to find out how to configure test targets in Xcode 6b4. Can someone point me in the right direction given this scenario.

I have a mostly Swift project. However, there are some 3rd party Objective-C dependencies, which get put into the application's bridging header. I want to write tests for my Swift code. Ideally, in Swift. The problem I have is this....

  1. If I create a Swift test case, then the compiler complains that it can't find the Objective-C headers in the application's bridging header.

  2. If I create an Objective-C test case, then I cannot import the Swift classes which I want to test.

The only thing which I can do is write Objective-C tests cases, which don't touch any Swift. I cannot write "purely Swift code/tests" due to the Objective-C dependencies.

Does anyone have any advice or had success on this. Or is this the current state of things in Beta 4?

7条回答
我想做一个坏孩纸
2楼-- · 2019-01-17 03:56

Try putting the #import "xyz-Swift.h" statements into your precompiled header files. That way you have different import statements for all of your Obj-C headers, depending on the target:

MyProject-Prefix.pch (app target):

#import "MyProject-Swift.h"

MyProjectTests-Prefix.pch (test target):

#import "MyProjectTests-Swift.h" 
查看更多
登录 后发表回答