swift 与oc 混编
发布时间:2020-12-14 07:08:49 所属栏目:百科 来源:网络整理
导读:oc 与swift 混编 创建oc一个项目 Swift_Objc oc 调用swift: 创建一个类SecondViewController,选择swift 语言,创建,提示是否进行桥接,点击桥接。 生成一个桥接文件Swift_Objc-Bridging-Header.h,这个文件在swift调用oc时学要用到。 在viewController,中
oc 与swift 混编
创建oc一个项目 Swift_Objc
oc 调用swift:
创建一个类SecondViewController,选择swift 语言,创建,提示是否进行桥接,点击桥接。
生成一个桥接文件Swift_Objc-Bridging-Header.h,这个文件在swift调用oc时学要用到。
在viewController,中引入Swift_Objc-Swift.h 文件,即可用oc 语言使用swift类
ViewController.h 文件中 调用代码:
- (void) presentVC { SecondViewController *secondVC = [[SecondViewController alloc]init]; [self presentViewController:secondVC animated:YES completion:nil]; }
swift 调用oc:
在Swift_Objc-Bridging-Header.h 文件中引入.h头文件,即可用swift语言调用oc类。
#import "ViewController.h" 在SecondViewController中调用 viewController override func touchesBegan(touches: Set<UITouch>,withEvent event: UIEvent?) { let vc = ViewController() self.presentViewController(vc,animated: true) { () -> Void in } }以后就是oc 与swift 混编 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |