Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

ios - How should a Swift + Objective-C project be setup for Unit Testing

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am not sure if you are still looking for this as Xcode 6 is not in beta any more, but you can add your Objective-C Bridging Header file to your Unit Test Target in the target settings. This fixed the issue for me.

Objective-C Bridging Header Xcode settings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...