Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ios - "XXX-Swift.h" file not found in test project

I'm trying to call a method of a NSObject subclass I have in the let's say "main" project within a method of a XCTestCase subclass in the test project. The NSObject subclass of the main project imports the "XXX-Swift.h" header file (I'm mixing Swift and Objective-C code). All works fine when I run the main project, but when I run the tests calling an object of that subclass, I get an error saying that the Swift header file in the import is not found.

I guess I'm missing some settings in the test target, but I don`t find which... what should I check? Or what should I do to solve this?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Go to Xcode Project > Build Settings and type "header name", you will get the below option:

enter image description here

Make sure that there must exist a file with a name: $(SWIFT_MODULE_NAME)-Swift.h

Then type, "bridging header" under Build Settings and make sure that the path of "bridging-header.h" file exist correctly.

enter image description here

Edited:

1) Make sure that your "Project Name" doesn't contains spaces 2) Well "XXX-Swift.h" file is generated at the following path, so you need to add that path to unit test - Go to build settings, type "Header Search Paths" and add the following line

"$(TARGET_TEMP_DIR)/../$(PROJECT_NAME).build/DerivedSources"

For more, you can refer this link : iOS - 'MyProject-Swift.h' file not found when running Unit Tests for Swift


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...