streetsofboston
12/29/2023, 9:34 PM@objc public protocol Parts {
var parts: [Part] { get }
}
@objc extension NSString: Parts {
@objc public var parts: [Part] {
return [.init(self)]
}
}
Objective-C equivalent:
SWIFT_PROTOCOL("_TtP8GoogleAi5Parts_")
@protocol Parts
@property (nonatomic, readonly, copy) NSArray<Part *> * _Nonnull parts;
@end
@interface NSString (SWIFT_EXTENSION(GoogleAi)) <Parts>
@property (nonatomic, readonly, copy) NSArray<Part *> * _Nonnull parts;
@end
How can I created a Parts
from a a String
in Kotlin given these declarations (or translate a String to a Parts-Protocol)?
Thanks!Jan Holešovský
01/02/2024, 2:17 PMstreetsofboston
01/02/2024, 2:35 PMParts
protocol as input to one of its methods/functions.
Eg. func doSomething(parts: Parts)
. I'd like to be able to call this function with just a String (or NSString).
In Swift, I can call this function with just an NSString (since it extends Parts): doSomething("hello")
However, in Kotlin, in the iosMain module, I can't do that: It complains that NSString
(or the Kotlin String
) is not conforming to the interface PartsProtocol
.Jan Holešovský
01/02/2024, 3:35 PMstreetsofboston
01/02/2024, 3:40 PMKotlinParts
(or something similar) and that KMP's cinterop would 'seamlessly' accept objective-c type extensions
I do have control over the cinterop and I'll add a(n overloaded) 'wrapper'/'adapter' method for this, that accepts a plain NSString (Kotlin String in iosMain)
Thanks!Jan Holešovský
01/03/2024, 6:15 AM