“ProductModuleName-Swift.h” not exporting all Swift classes

為{幸葍}努か 提交于 2019-12-12 01:56:23

问题


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

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)

This class is being exported:

class SearchViewController : UIViewController {

but this isn't:

public class Socket {

回答1:


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

  • 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.

  • 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 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 { ...

or declare it as

@objc public class Socket { ...


来源:https://stackoverflow.com/questions/25605677/productmodulename-swift-h-not-exporting-all-swift-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!