Richard Topchii
Richard Topchii

Reputation: 8215

Importing modulename-Swift.h file to ObjC .h file

Is it possible to import the modulename-Swift.h file to another .h file, so that the test target also would compile?

Currently, I was importing the modulename-Swift.h in the one of the headers of the app's target, however, the test target was not able to compile.

When I moved the import statement to the .m file instead, I was able to compile both, the app and the tests.

However, I have to resort to a forward protocol declaration in order to resolve this issue - the modulename-Swift.h file contains a protocol.

So, the question is whether I can import that file in .h file at all?

Upvotes: 0

Views: 682

Answers (1)

mikepj
mikepj

Reputation: 1338

No, you can't import modulename-Swift.h in a .h file. You'll need to create forward declarations (adding @protocol Something; to your .h) and import the Swift module in the .m file.

Another way to work around this is to declare the protocol conformance in a category in the .m file. More details can be found in this StackOverflow answer:

https://stackoverflow.com/a/27626493/3208043

Upvotes: 1

Related Questions