ios - 如何在基于 Swift 的项目中使用基于 Objective-C 的框架?

标签 ios objective-c swift

我有一个基于 Objective-C 的 cocoa pod 框架。这个框架有一个带有 XIP View Controller 的类。我想从一个基于 Swift 的项目访问这个 Controller 。下面的代码是 Objective-C 代码。我需要在基于 Swift 的项目中使用它。

ViewController * viewController = [[ViewController alloc] initWithNibName:@“VController” bundle:nil];
viewController.delegate = self;
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[vc presentViewController: viewController animated:true completion:nil];

最佳答案

这很简单,只需遵循一些步骤,您就可以做到这一点

我有一个项目,我正在我的 swift 项目中使用 RIOInterface.h Obj-c

第 1 步-只需在 Swift 项目中添加 Objective c 文件

我在我的项目中添加了 RIOinterface.h 和 .mm

enter image description here

第 2 步 之后您只需拖放 Obj-c 类 现在弹出窗口将显示为

enter image description here

->点击是

第 3 步-现在在创建的桥接类中导入您的 Obj-C header

enter image description here

第 4 步-您已完成配置步骤 现在,是时候使用该类了

因为,我为那个类创建了一个对象

enter image description here

现在将它与创建的对象一起使用,如下所示

enter image description here

您在 Swift 中访问了您的 Objective-C 代码

关于ios - 如何在基于 Swift 的项目中使用基于 Objective-C 的框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48143708/

相关文章:

swift - 将多个 .sks 文件连接到 SpriteKit 中的多个 .swift 文件

ios - 具有从右到左文本和自动调整字体大小的多行 UILabel

android - 我可以在 React Native 中要求专门针对 iOS 的模块吗?

ios - 单击 uitableviewcell 时使用 Actionsheet 而不是 segue

ios - self.property = objective-c 中的 self.property

ios - 将NSMutableDictionary转换为NSArray的最简单方法

ios - TableViewController 导航栏标题不加粗

ios - Swift 中的向上滑动动画

c++ - Objective-C 变量在 C++ 中读取为 null

swift - 当我在异步回调中设置一个对象时会发生什么?