我正在做苹果文档中写的相同步骤。但是我无法在目标c文件中访问swift类。
代码:
斯威夫特文件
import Foundation
import UIKit
@objc class checkk : UIViewController {
func alertView ()
{
let al = UIAlertView(title: "HeLLo", message: "Working", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "ww", "sdd")
al.show()
}
}
目标C文件
#import "ViewController.h"
#import "SwiftIntoObjectiveC-Bridging-Header.h" // automatically generated by Xcode. Nothing is written in this.
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
checkk *ck =[checkk new]; // error : use of undeclared identifier check.
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)Click:(id)sender {
}
@end
错误:使用未声明的标识符检查。
在Objective-C中,用于访问Swift类的导入看起来像这样:
#import "YOUR_APP_NAME-Swift.h"
其中,YOUR_APP_NAME实际上是目标的模块名称,但通常与您的应用程序相同。
该文件包含了Objective-C访问Swift中定义的符号所必需的Swift原型。
在您的情况下,您的模块名称可能是,SwiftIntoObjectiveC
并且您可能可以使用
#import "SwiftIntoObjectiveC-Swift.h"
桥接头永远不会导入到Objective-C中,因为它不被Objective-C端使用,仅用于提供对Swift端的Objective-C符号的访问。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句