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 混编