"ProductModuleName-Swift.h" does not export all Swift classes

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

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

This class is exported:

 class SearchViewController : UIViewController { 

but this is not so:

 public class Socket { 
0
source share
1 answer

From “Porting Objective-C Code to Swift” in the documentation “Using Swift with Cocoa and Objective-C”:

  • To be accessible and useful in Objective-C, the Swift class must be a descendant of the Objective-C class or must be marked as @objc.

  • When you enter Swift code in Objective-C, remember that Objective-C will not be able to translate some functions that are specific to Swift. See "Using Swift from Objective-C" for a list.

SearchViewController is a descendant of the Objective-C class, but Socket 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 { ... 
+4
source

Source: https://habr.com/ru/post/975413/


All Articles