ios - 将 Swift 导入 Objective-C

标签 ios objective-c swift

添加 .swift 文件时,我没有收到要求自动创建桥接文件的提示(可能是因为我可能按了一次“否”)。虽然苹果文档说:

When you import Swift code into Objective-C, you rely on an Xcode-generated header file to expose those files to Objective-C.

这意味着,您不能自己手动制作 MyProjectName-Swift 文件,就像将 Objective-C 代码导入 Swift 项目时可以制作的那样。

我应该怎么做才能引入要求自己创建桥接文件的该死的提示?

附言我只有一个 Target,我只想导入几个 .swift 文件。

最佳答案

根据 HamG 的评论,MyProjectName-Swift 是自动创建的,它不会出现在项目文件浏览器中。 添加后,我们就可以直接使用了。您无需将其放在 Build Settings -> Objective-C Bridging Header 中的任何路径 要使用 swift 文件,只需将 import 语句放入:

#import "MyProductModuleName-Swift.h"

并使用任何 swift 类,它应该出现在代码完成列表中。

ProjectModuleName 可以在 Build Settings-> Product Module Name 中找到

关于ios - 将 Swift 导入 Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30910217/

相关文章:

ios - 单击 UIWebview 上的链接时打开 UIView

ios - 为什么 UICollectionView 不滚动其中的 UIButtons?

ios - 识别 iOS 文件包(在 Simulator 和 Finder 中)

objective-c - Objective-C : Uploading and downloading from a server

ios - 如何获取当前 CLLocation 或 CLPlacemark 的 USA Region 和 Division?

ios - 静态 TableView 获取 NSRangeException

ios - 日历的 UICollectionView 中有多少个单元格开始? (即具有无限数量的日期)

iphone - UILocalNotification - 即使应用程序通过主屏幕启动也响应通知

iphone - 导出 CoreData 的快捷方式是什么?

swift - 从 AVSpeechSynthesisVoice 获取国家/地区列表