Darron Schall
09/15/2023, 5:47 PMDarron Schall
09/15/2023, 5:47 PM// In NSDateExtensions.kt
fun NSDate.toInstant() = Instant.fromEpochSeconds(timeIntervalSince1970.toLong(), 0)
requires me to use NSDateExtensionsKt.toInstant(date)
in Swift:
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("NSDateExtensionsKt")))
@interface SharedNSDateExtensionsKt : SharedBase
+ (SharedKotlinx_datetimeInstant *)toInstant:(NSDate *)receiver __attribute__((swift_name("toInstant(_:)")));
@end
However, this extension:
// In ByteArrayExtensions.kt
fun ByteArray.md5base64(): String = toByteString().md5().base64()
let's me call the extension byteArray.md5base64()
directly:
@interface SharedKotlinByteArray (Extensions)
- (NSString *)md5base64 __attribute__((swift_name("md5base64()")));
@end
I would always prefer my extensions end up in an Objective-C (Extensions)
category, so that I can use the extensions the same way in Swift and Kotlin. It's frustrating to run into a compiler error that the extension doesn't exist, and then have to look up the shared.h
header only to find that I need to go through the "ExtensionsKt" extension class helper.
This is a small thing, not really important.. but I'm curious if there's something I can do to help force the (Extensions)
category for K/N code gen.Darron Schall
09/15/2023, 5:50 PMRick Clephas
09/15/2023, 6:08 PMRick Clephas
09/15/2023, 6:09 PMNSDate
is an ObjC type and ByteArray
is a regular Kotlin type.Darron Schall
09/15/2023, 6:13 PM