iOS 在OC旧项目中使用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];
  • 在swift中调用oc:在桥接文件中引入要使用的oc类
在 TestOcSwitchSwift-Bridging-Header.h 中
#import "FirstViewController.h"
//在需要使用的地方直接调用。例如:在这里直接跳转页面
 let tmpVC = FirstViewController()
 tmpVC.modalPresentationStyle = .fullScreen
 present(tmpVC, animated: true, completion: nil)

相关推荐

  1. Swift OC冲突方法探索

    2024-04-23 09:04:03       56 阅读
  2. Swift集成Socket.IO进行实时通信

    2024-04-23 09:04:03       44 阅读
  3. iOS OCSwift文件相互调用

    2024-04-23 09:04:03       61 阅读
  4. iOS的@objc和@objcMembers实现SwiftOC的交互

    2024-04-23 09:04:03       30 阅读
  5. Go项目使用ELK进行日志采集

    2024-04-23 09:04:03       38 阅读
  6. Swift , enumerated() 有哪些常用的使用方式 ?

    2024-04-23 09:04:03       47 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-23 09:04:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-23 09:04:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-23 09:04:03       87 阅读
  4. Python语言-面向对象

    2024-04-23 09:04:03       96 阅读

热门阅读

  1. IDM的实用功能

    2024-04-23 09:04:03       32 阅读
  2. markdown语法转换成html渲染到页面

    2024-04-23 09:04:03       40 阅读
  3. MongoDB的UTCDateTime如何使用

    2024-04-23 09:04:03       34 阅读
  4. milvus 相似度检索的底层原理

    2024-04-23 09:04:03       35 阅读