Hello :wave: Has anyone had experience creating ex...
# multiplatform
a
Hello đź‘‹ Has anyone had experience creating extension functions for Floats in
common
which then translate to appropriate usages for Swift/iOS? For example:
Copy code
data class Measurement(val type:String, val value:Float)

fun Float.metres() = Measurement("Metre", this)
What I currently end up with being generated on the iOS side in the header file is given the extension function lives in the file `FloatExt.kt`:
Copy code
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("FloatExtKt")))
@interface FloatExtKt : KotlinBase
+ (Measurement *)metres:(float)receiver __attribute__((swift_name("metres(_:)")));
@end
Which suggests that it’s not an extensions on the iOS “float” type but accessible via
FloatExtKt.metres()
🤔
m
Extensions on Objective-C classes are not supported in the interop, so you end up with this.
t
For these kind of things, I always have a Swift file with Swift extensions that wrap these to be used nicely anywhere else in the project.