iOS - 在 Objective-c 和 Swift 上一起实现 UI [英] iOS - Implementing UI on Objective-c and Swift together
问题描述
一个遗留项目是在 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 yourSwift
file just import thatObjective-C
file into yourBridge-Header
. - If you want to use
Swift
class file into yourObjective-C
controller so import "ProjectName-Swift.h" into yourObjective-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"
这篇关于iOS - 在 Objective-c 和 Swift 上一起实现 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!