Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use Swift classes inside Objective-C unit test

I have followed this recipe in order to use a Swift class in an existing Objective-C project MyProject. That works fine.

However, I'm still not able to use the same Swift class in the same project's unit tests. The compiler marks the line where my Objective-C unit test says #import "MyProjectTests-Swift.h" with file not found.

If tried changing the test target's Product Module Name from its default MyProjectTests to MyProject as suggested in a comment to this (unanswered) question. However the compiler now marks the line where my Objective-C unit test says #import "MyProject-Swift.h" with file not found.

So how can one integrate Swift classes into (XCTest) unit tests that are written in Objective-C? Does Apple provide any recipe?

like image 845
Drux Avatar asked Jan 23 '15 16:01

Drux


1 Answers

Step-1

Go to your test target > Build Settings > Header Search Paths, and add $CONFIGURATION_TEMP_DIR/YourProject.build/DerivedSources in it.

Step-2

#import "YourProject-Swift.h"

like image 90
Harry Zhang Avatar answered Oct 18 '22 17:10

Harry Zhang