I noticed recently that Kotlin extensions are no longer exposed to ObjC/Swift as extensions, but instead as classmethods on a somewhat unusually named class... I'm pretty sure that they actually appeared as extensions using an earlier build though. What is the reason for the change? Will be extensions be returning at some point? (Or am I just mistaken?)
s
svyatoslav.scherbina
06/30/2018, 5:30 AM
Kotlin extensions to some types are exposed as extensions to ObjC/Swift, while extensions to other types aren’t:
Could you provide an example of extension which translation has been changed?
d
damian
06/30/2018, 8:05 AM
Hmm you are probably right and I'm misremembering. Why are extensions on Kotlin types not exposed as extensions?
s
svyatoslav.scherbina
06/30/2018, 8:50 AM
Extensions to some Kotlin types aren't exposed as extensions due to limitations of Objective-C language or/and technical limitations and complexity.
d
damian
07/02/2018, 5:03 PM
@svyatoslav.scherbina Any chance you could elaborate on "some Kotlin types" (is this documented anywhere?) and/or what the limitations and additional complexities are? Partially for curiosity, but I would also like to know if there's anything I can do to make "extension-compatible" types.
s
svyatoslav.scherbina
07/03/2018, 7:16 AM
Currently Kotlin/Native exposes only extensions to Kotlin classes that are not interfaces and are not collections/functions/strings etc.
Objective-C doesn’t have any kind of extensions to protocols, and all extensions to classes (i.e. category methods) are added to virtual dispatch and thus can unexpectedly clash with other methods at runtime, so we avoid adding methods to
NSString
, Cocoa collections and other standard classes.
d
damian
07/03/2018, 2:48 PM
Thanks for the explanation, @svyatoslav.scherbina! That makes sense. simple smile