0

我正在尝试将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"
4

1 回答 1

2

如果您在 objc 类中使用 Swift 文件,桥接头在这里将无济于事。

Xcode 将创建您需要导入的头文件

首先转到构建设置并搜索定义模块并将其设置为 true。

现在在.m文件中添加以下头文件

#import "YourTargetName-Swift.h" 

并构建项目

@objc在您的财产之前添加

希望对您有所帮助

于 2018-05-24T14:27:20.990 回答