“ProductModuleName-Swift.h"不导出所有 Swift 类 [英] "ProductModuleName-Swift.h" not exporting all Swift classes

查看:28
本文介绍了“ProductModuleName-Swift.h"不导出所有 Swift 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Xcode 项目中定义了两个 Swift 类.其他一切都是Objective-C.

I have defined two Swift classes in my Xcode project. Everything else is Objective-C.

为了使用 Objective-C 中的类,我尝试导入 ProductModuleName-Swift.h 但该文件仅包含 Swift 类之一的定义.(SearchViewController)

To use the classes in Objective-C I'm trying to import ProductModuleName-Swift.h but the file contains only the definition for one of the Swift classes. (SearchViewController)

正在导出这个类:

class SearchViewController : UIViewController {

但这不是:

public class Socket {

推荐答案

来自 将您的 Objective-C 代码迁移到 Swift",在将 Swift 与 Cocoa 和 Objective-C 结合使用"文档中:

From "Migrating Your Objective-C Code to Swift" in the "Using Swift with Cocoa and Objective-C" documentation:

  • 要在 Objective-C 中访问和使用,Swift 类必须是 Objective-C 类的后代,或者必须标记为 @objc.

  • To be accessible and usable in Objective-C, a Swift class must be a descendant of an Objective-C class or it must be marked @objc.

当您将 Swift 代码引入 Objective-C 时,请记住,Objective-C 将无法翻译某些特定于 Swift.有关列表,请参阅 "使用 SwiftObjective-C".

When you bring Swift code into Objective-C, remember that Objective-C won’t be able to translate certain features that are specific to Swift. For a list, see "Using Swift from Objective-C".

SearchViewController 是 Objective-C 类的后代,但 Socket 不是.要使其在 Objective-C 中可用,请将其声明为 NSObject 的子类:

SearchViewController is a descendent of an Objective-C class, but Socket is not. To make it usable in Objective-C, declare it as a subclass of NSObject:

public class Socket : NSObject { ...

或声明为

@objc public class Socket { ...

这篇关于“ProductModuleName-Swift.h"不导出所有 Swift 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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