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
358 views
in Technique[技术] by (71.8m points)

ios - import swift class in objective-c, <myModule>-Swift.h file not found

I have an iOS project written with Objective-C. I created an Swift class in the project, the bridging header file for accessing objective-c in Swift is generated successfully, and it works fine.

My problem is the other way around. I want to import Swift class in objective-c code.

In xcode, target -> Build Settings--> Swift Compiler section, I see Objective-C Generated Interface Header Name field with value myModule-Swift.h , but when I import this header in my objective-c class:

#import "myModule-Swift.h"

I get compiler error:

myModule-Swift.h file not found

and in project, I cannot find this file either. How can I solve this problem?

My xcode version is 6.4

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Updated May 2018 Xcode 9.3


  1. Build Settings->Objective-C Generated Interface Header Name
    and set the value to YourModule-Swift.h (this is usually already set, this is the filename you need to import on .m file #import "YourModule-Swift.h"

(Example, Project named CData)

Example

  1. Same as Step 1, Go to Build Settings and search for "Defines Module", set both values to YES

  2. Create a class that extends NSObject on .swift file

Example

  1. Build the project again

  2. Import YourModule-Swift.h file on .m file (Please notice it's case sensitive, Mymodule !== MyModule)

enter image description here


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

...