我正在尝试将int
从objective-c文件传递给swift。
我所采取的步骤确实有所不同,但遗憾的是,由于以下错误,它没有通过int:Property 'productKey' not found on object of type 'ProductViewController *'
准备Segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"viewProduct"]) {
ProductViewController *destVC = segue.destinationViewController;
destVC.productKey = brandID;
}
}
执行Segue
dispatch_async(dispatch_get_main_queue(), ^(){
[self performSegueWithIdentifier:@"viewProduct" sender:self];
});
Swift文件
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"
答案 0 :(得分:2)
如果你在objc类中使用Swift文件,Bridging header在这里没有帮助。
Xcode将创建您需要导入的头文件
首先转到构建设置并搜索定义模块并将其设置为true。
现在在.m
文件中添加以下头文件
#import "YourTargetName-Swift.h"
并构建项目
并在您的财产
之前添加@objc
希望它有用