我需要从 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/