我正在尝试将一个简单的字符串从swift控制器传递到Objective-C控制器,但不幸的是它不起作用。
错误我获取:
类型的" euidviewController"类型的值没有成员'字符串''
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"到Bridging-Header
您需要在 .h
中声明 stringPassed
属性表示该 ViewController
的标头文件。
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString* stringPassed;
@end