How can I import Swift code to Objective-C?

前端 未结 15 2444
南方客
南方客 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:34

    You need to import ProductName-Swift.h. Note that it's the product name - the other answers make the mistake of using the class name.

    This single file is an autogenerated header that defines Objective-C interfaces for all Swift classes in your project that are either annotated with @objc or inherit from NSObject.

    Considerations:

    • If your product name contains spaces, replace them with underscores (e.g. My Project becomes My_Project-Swift.h)

    • If your target is a framework, you need to import

    • Make sure your Swift file is member of the target

提交回复
热议问题