将数据从 Swift 控制器传递到 Objective-C 控制器

Passing data from a Swift Controller to an Objective-C controller

我试图将一个简单的字符串从 Swift 控制器传递到 Objective-C 控制器,但不幸的是它不起作用。

错误我得到:

Value of type 'EUIDViewController' has no member 'stringPassed'

Swift 代码发送字符串

let pvc = EUIDViewController(nibName: "ScannerViewController", bundle: nil)
if isHasCameraPermission {
    pvc.stringPassed = "test"
    present(pvc, animated: true, completion: { _ in })
}

Objective-C 接收字符串的代码

@property (strong, nonatomic) NSString* stringPassed;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initOCR];
    NSLog(@"String: %@", self.stringPassed);
}

更新:我#import "EUIDViewController.h" 到桥接头

您需要在.h中声明stringPassed 属性表示ViewController的头文件。

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString* stringPassed;

@end