How can I import Swift code to Objective-C?

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

    Search for "Objective-C Generated Interface Header Name" in the Build Settings of the target you're trying to build (let's say it's MyApp-Swift.h), and import the value of this setting (#import "MyApp-Swift.h") in the source file where you're trying to access your Swift APIs.

    The default value for this field is $(SWIFT_MODULE_NAME)-Swift.h. You can see it if you double-click in the value field of the "Objective-C Generated Interface Header Name" setting.

    Also, if you have dashes in your module name (let's say it's My-App), then in the $(SWIFT_MODULE_NAME) all dashes will be replaced with underscores. So then you'll have to add #import "My_App-Swift.h".

提交回复
热议问题