I’ve added an extension function in Kotlin to an o...
# kotlin-native
s
I’ve added an extension function in Kotlin to an objc framework. It’s showing up in Swift code though as a function that you have to pass an instance into. Here is the objc header:
Copy code
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("RallyAbTestKt")))
@interface RATRallyAbTestKt : RATBase
+ (void)getExperimentGroup:(id<RATRallyAbTest>)receiver name:(NSString *)name callback:(void (^)(NSString *))callback __attribute__((swift_name("getExperimentGroup(_:name:callback:)")));
+ (void)doInit:(id<RATRallyAbTest>)receiver appName:(NSString *)appName userIdentifier:(NSString *)userIdentifier experiments:(NSArray<RATExperiment *> *)experiments mode:(RATAbTestMode *)mode callback:(void (^)(NSArray<RATExperimentGroup *> *))callback __attribute__((swift_name("doInit(_:appName:userIdentifier:experiments:mode:callback:)")));
@end;
The interop documentation shows that it should show up as an extension in Swift. Do I have to do something special to get that to work?
b
is it an extension on a kotlin interface?
s
its an extension on an interface
b
Obj-C doesn't have a parallel concept
Swift has protocol extensions
Obj-C does not 😕
s
I have an interface
RallyAbTest
, and I’m adding a platform specific
init
function for
the documentation shows that the bridge shows them as extensions
however - after reading the note, perhaps it only works from objc / Swift to Kotlin. Not vice versa
b
yes, but part of all of that is the caveat about it only supports what Obj-C supports
extensions work, but only extensions on classes
since Obj-C supports that
s
oh interesting.