我正在尝试将 int
从 objective-c 文件传递到 swift。
我所采取的步骤确实是 segue,但遗憾的是,由于以下错误,它没有传递 int:Property 'productKey' not found on object of type 'ProductViewController *'
准备转场
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"viewProduct"]) {
ProductViewController *destVC = segue.destinationViewController;
destVC.productKey = brandID;
}
}
执行转场
dispatch_async(dispatch_get_main_queue(), ^(){
[self performSegueWithIdentifier:@"viewProduct" sender:self];
});
快速文件
class ProductViewController: UIViewController {
var productKey: Int!
override func viewDidLoad() {
super.viewDidLoad()
print(productKey)
}
}
头桥
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "ARSceneViewController.h"
最佳答案
如果您在 objc 类中使用 Swift 文件,桥接 header 在这里无济于事。
Xcode 将创建您需要导入的头文件
首先转到build设置并搜索 Defines Modules 并将其设置为 true。
现在在.m
文件中添加如下头文件
#import "YourTargetName-Swift.h"
并构建项目
并且在你的属性之前添加@objc
希望对你有帮助
关于ios - 从 Obj-c 到 swift 的 Segue 找不到属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50511740/