我的项目使用的是 Swift 3.0,我使用的是 xCode8.2。我需要在我的 swift 项目中导入 Objective-C 代码。 Objective-C 需要应用程序委托(delegate)引用。如何从我的 Objective-C 代码中获取 swift appdelegate 引用?
在我的 Objective-C 文件中,#import "AppDelegate.h"给出了未找到的错误,因为它是快速的 AppDelegate
最佳答案
正如 Kie 所说,您需要 #import "<ProductModuleName>-Swift.h"
在你的 Obj-C .m
文件以获取所有 Swift 类。这是一个包含您需要的示例项目 https://github.com/aminbenarieb/Researches/tree/master/Swift/Swift_ObjC .
更新:
如果您在 Objective-C 文件中看不到 Swift 文件,请确保您有 Objective-C bridging header
,如下在Apple Documentation:
Importing Objective-C into Swift
To import a set of Objective-C files in the same app target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app.
关于objective-c - 我如何从 objective-c 代码中获取 Swift AppDelegate 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42506778/