Call Swift function from Objective-C class

Problem Solved, I previously create and included a new .h file in my Objective-C class named <ProductModuleName>-Swift.h but, as i discovered later, this step is not necessary because the compiler creates the necessary file invisible.

Simply include <ProductModuleName>-Swift.h in your class and it should work.


It is strange but will work after we do:

  1. Add @objc to your Swift-class ("MySwiftClass").

  2. Add in Obj-C, i.e. the .m file:

    #import "(ProjectName)-Swift.h"
    
  3. Declare in header .h

    @class MySwiftClass;
    

Compiler will generate the interface for @objc marked class in MyModuleName-Swift.h file.

Auto-Generated Obj-C Example:

SWIFT_CLASS("_TtC10Project17220PLHelper")
@interface PLHelper

+ (void)notifyForDownloading:(NSDictionary *)userInfo;
- (instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end