简体   繁体   English

将Swift代码导入Objective-C文件

[英]Import Swift code to Objective-C file

I have created a Swift project and imported Objective-C files. 我创建了一个Swift项目并导入了Objective-C文件。 During import Xcode asked me to create a bridging header and created a header. 在导入过程中, Xcode要求我创建一个桥接标题并创建一个标题。

Now in the Objective-C files of the same project I want to use Swift class methods. 现在在同一项目的Objective-C文件中我想使用Swift类方法。 I googled about importing Swift code in an Objective-C file. 我搜索了在Objective-C文件中导入Swift代码。 I found that we have to import ProjectName-Swift.h in the Objective-C file. 我发现我们必须在Objective-C文件中导入ProjectName-Swift.h My questions are as follows: 我的问题如下:

  1. ProjectName-Swift.h is not been created by Xcode. ProjectName-Swift.h不是由Xcode创建的。 How do I create that file? 我该如何创建该文件?
  2. After creation of ProjectName-Swift.h file, how do I use the Swift file methods in Objective-C files? 创建ProjectName-Swift.h文件后,如何在Objective-C文件中使用Swift文件方法?

This seems really messed up, but the ProjectName-Swift.h file isn't visible. 这似乎搞砸了,但ProjectName-Swift.h文件不可见。 You just have to #import ProjectName-Swift.h in your Obj-C classes, and it'll work. 你只需要在你的Obj-C类中#import ProjectName-Swift.h ,它就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在框架项目的 Objective-C 代码中导入 Swift 类 - Unable to import Swift class in Objective-C code in a framework project 如何将swift文件导入Objective-C类,以进行类委派? - How to import swift file to objective-c class, for class delegation? 在Objective-C项目的Swift文件中导入Objective-C类 - Import Objective-C class in Swift file in Objective-C Project 将Objective-C Framework(CocoaPod)导入Swift? - Import Objective-C Framework (CocoaPod) into Swift? swift build errors from Objective-C app due to import of Objective-C static library that contains a.swift file - swift build errors from Objective-C app due to import of Objective-C static library that contains a .swift file 如果包含Project-Swift.h的导入,如何将Objective-C文件导入桥接头 - How to import Objective-C file to bridging header if it contains an import of Project-Swift.h 在objective-c中导入swift类,<myModule> -Swift.h 文件未找到 - import swift class in objective-c, <myModule>-Swift.h file not found 将 Objective-C 转换为 Swift 代码 - Converting Objective-C to Swift Code 将PinchRecognizer Objective-C代码转换为Swift - Convert PinchRecognizer Objective-C code to Swift Swift中带有#define宏的Objective-C代码 - Objective-C code with #define macros in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM