ios - 从 objective c 转到 swift

标签 ios objective-c swift

我需要从 Objective C View Controller 转到 Swift View Controller ,并将数据传递给新的 View Controller 。

在 Objective-C 中,我会:

#include "SecondViewController.h"

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
   SecondViewController *svc = [segue destinationViewController];
   svc.property = self.property;
}

当转至 Swift View Controller 时,我如何完成相同的操作?

我已经尝试包含“SecondViewController.swift”,但这只会引入错误并且不允许我在 PrepareForSegue 中使用 SecondViewController *svc:无论如何。

最佳答案

您必须导入名称为<module_name>_Swift.h 的swift 桥头文件。 .例如,如果您的项目名为 MyProject :

#import "MyProject-Swift.h"

请注意,这不是用于将 objc 代码公开给 swift 的桥接 header ,名为 <module_name>-Bridging-Header.h

关于ios - 从 objective c 转到 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28149650/

相关文章:

Swift:For Loop 按大于 1 的索引遍历枚举数组

objective-c - Objective-C 之外有什么类似于 Grand Central Dispatch 的东西吗?

objective-c - 在 objective-c 中定义和使用协议(protocol)

ios - 如何在 Swift 中更改 UIPickerView 组件的字体大小?

ios - 自定义 iOS 框架文件中捆绑的 Storyboard

iphone - 连续显示多个 CALayer 60 秒?

objective-c - 将 View 添加到 ScrollView

ios - 如何让基于 CocoaPods 的项目在模拟器中运行?

iOS Paypal MPL 开发者错误

xcode - 检查系统音量是否静音