1

I have a Swift framework in which I have an Objective-C file. From that file I want to access a method which is declared as internal. I know that I can change it to public to make it available. But I don't want to expose it to the client app. Is there any way to achieve this?

In .swift:

@objc internal class func callBack(str: String) {
    print("Swift method was called | Passed value: " + str)
}

In .m:

- (void)callSwiftFunc {
    // This is not available, only if I set public in Swift
    [SwiftClass callBackWithStr:@"blabla"];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kristof
  • 33
  • 4

1 Answers1

1

You can explicitly set the objc selector and then add a category which declares the method:

replace @objc with @objc(callBackWithStr:), then simply add a forward declaration:

@interface SwiftClass ()
+ (void)callBackWithStr:(NSString *)string;
@end
lukas
  • 2,300
  • 6
  • 28
  • 41