objective-c - 我如何从 objective-c 代码中获取 Swift AppDelegate 的引用

标签 objective-c swift

我的项目使用的是 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/

相关文章:

objective-c - 是否有用于 Twitter 的 iPhone SDK API?

ios - 带有核心数据的通用主从应用程序和 iphone Storyboard的选项卡 Controller 获取无法识别的选择器发送到实例错误

core-data - ManagedObjectModel 子类在 Swift 中不起作用

ios - 如何在一周中的特定一天但每隔一周运行一次通知(Swift + Xcode)?

ios - RealityKit 仅显示暗图像

swift - 是否可以从枚举方法内部更改枚举?

ios - 表格 View 滚动平滑与 url 图像

objective-c - 在 Objective-C 中调用动态类的方法?

iphone - 在 ios 5 的 MP 音乐播放器 Controller 中获得错误的播放状态

ios - 如何从新的 Firebase 存储下载和查看图像?