How to export a “static method” in kotlin to a “cl...
# kotlin-native
l
How to export a “static method” in kotlin to a “class method” in objective-c? I have a object class like this in kotlin:
Copy code
object LogUtil {

  fun log(message: String) {
    
  }
}
but export to ios framework, the class defined like this:
*__attribute__*((objc_subclassing_restricted))
*__attribute__*((swift_name("LogUtil")))
*@interface* CommonLogUtil : KotlinBase
+ (
*instancetype*)alloc *__attribute__*((unavailable));
+ (
*instancetype*)allocWithZone:(*struct* _NSZone *)zone *__attribute__*((unavailable));
+ (
*instancetype*)logUtil *__attribute__*((swift_name("init()")));
- (
*void*)logMessage:(NSString *)message *__attribute__*((swift_name("log(message:)")));
*@end*;
As code shows that “logMessage” method is not a “class method”, the expected result maybe like this:
+ (*void*)logMessage:(NSString *)message *__attribute__*((swift_name("log(message:)")));
k
It’s kind of a quirk of the objc interop, but you access it like it’s a class.
Copy code
LogUtil().log(message: "abc")
It’s not creating a new instance every time, however.
👍 1
l
But the code shows it create a new instance every time, so weird, I will try it, thank you!