iOS - 在 Objective-c 和 Swift 上一起实现 UI [英] iOS - Implementing UI on Objective-c and Swift together

查看:27
本文介绍了iOS - 在 Objective-c 和 Swift 上一起实现 UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个遗留项目是在 Objective-c 上完成的,其中有一个选项卡视图.我想在 Swift 上实现一个新选项卡需要一个全新的功能.现在没有时间将整个项目转换为 Swift,但新功能将在 Swift 上实现.谁能指导我如何在 Swift 中实现新功能,只需在 Objective-c UI 上添加一个新选项卡.

A legacy project was done on Objective-c, where there is a tab view. A full new feature is required with a new tab which I want to implement on Swift. Right now there is no time to convert full project into Swift but the new feature is to be implemented on Swift. Can anyone guide me how can I implement the new feature in Swift just adding a new Tab on Objective-c UI.

推荐答案

您可以自信地开始在您的 Objective-C 项目中使用 Swift 文件.无需将整个项目转换为 Swift

You can confidently start using Swift files in your Objective-C project. There is no need to convert full project into Swift

您可以按照以下步骤在您的项目中使用 Swift 类:

You can follow below steps to use Swift class in your project:

  • Swift 中创建新的控制器类.
  • 它会弹出Bridge-Header文件,创建它.
  • 如果您想在您的 Swift 文件中使用任何 Objective-C 类,只需将该 Objective-C 文件导入您的 桥头.
  • 如果您想在 Objective-C 控制器中使用 Swift 类文件,请导入ProjectName-Swift.h"到您的 Objective-C控制器类.
  • Create new Controller Class in Swift.
  • It will pop up for Bridge-Header file, create it.
  • If you want to use any Objective-C class into your Swift file just import that Objective-C file into your Bridge-Header.
  • If you want to use Swift class file into your Objective-C controller so import "ProjectName-Swift.h" into your Objective-C controller class.

重要: "ProjectName-Swift.h" 将是模块名称.如果您的项目中有多个目标,请使用 "TargetName-Swift.h"

important : "ProjectName-Swift.h" would be Module name. If you have multiple targets in your project the use "TargetName-Swift.h"

请点击以下链接:https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

如何从 Swift 调用 Objective-C 代码

如何将 Swift 代码导入 Objective-C

这篇关于iOS - 在 Objective-c 和 Swift 上一起实现 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆