How can I import Swift code to Objective-C?

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

    There's one caveat if you're importing Swift code into your Objective-C files within the same framework. You have to do it with specifying the framework name and angle brackets:

    #import

    MyFramework here is the "Product Module Name" build setting (PRODUCT_NAME = MyFramework).

    Simply adding #import "MyFramework-Swift.h" won't work. If you check the built products directory (before such an #import is added, so you've had at least one successful build with some Swift code in the target), then you should still see the file MyFramework-Swift.h in the Headers directory.

提交回复
热议问题