当前位置:   article > 正文

iOS 在OC旧项目中使用Swift进行混编_ios 混编 swift

ios 混编 swift

iOS 在OC旧项目中使用Swift进行混编

在这里插入图片描述

1、创建桥接文件

​ 第一次在Swift创建OC文件,或者第一次OC创建Swift时,xcode会提示桥接,Creat Bridging Header即可,这个文件用于Swift调用OC文件,与OC调用Swift无关。

2、在TARGETS中设置Defines Module

​ TARGETS ->Build Settings -> Packaging 中 设置Defines Module为YES

3、如何使用
  • 在OC中调用swift:在需要使用swift文件的oc类中,添加头文件 #import “项目名称-Swift.h”
#import "TestOcSwitchSwift-Swift.h"
SwiftViewController * tmpVC = [[SwiftViewController alloc]init];
[tmpVC setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:tmpVC animated:YES completion:nil];
  • 1
  • 2
  • 3
  • 4
  • 在swift中调用oc:在桥接文件中引入要使用的oc类
在 TestOcSwitchSwift-Bridging-Header.h 中
#import "FirstViewController.h"
//在需要使用的地方直接调用。例如:在这里直接跳转页面
 let tmpVC = FirstViewController()
 tmpVC.modalPresentationStyle = .fullScreen
 present(tmpVC, animated: true, completion: nil)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号