How can I import Swift code to Objective-C?

前端 未结 15 2418
南方客
南方客 2020-11-22 02:52

I have written a library in Swift and I wasn\'t able to import it to my current project, written in Objective-C.

Are there any ways to import it?

#i         


        
15条回答
  •  广开言路
    2020-11-22 03:22

    Importing Swift file inside Objective-c can cause this error, if it doesn't import properly.

    NOTE: You don't have to import Swift files externally, you just have to import one file which takes care of swift files.

    When you Created/Copied Swift file inside Objective-C project. It would've created a bridging header automatically.

    Check Objective-C Generated Interface Header Name at Targets -> Build Settings.

    Based on above, I will import KJExpandable-Swift.h as it is.

    Your's will be TargetName-Swift.h, Where TargetName differs based on your project name or another target your might have added and running on it.

    As below my target is KJExpandable, so it's KJExpandable-Swift.h

提交回复
热议问题