https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

alex.hart

10/29/2018, 5:24 PM
Does Kotlin Multiplatform support native generic type parameters? Or are they stripped?
r

Ruckus

10/29/2018, 6:02 PM
What do you mean by "native generic type parameters"?
a

alex.hart

10/29/2018, 6:26 PM
Example, I’ve got a class:
Copy code
public abstract class A<T> {
}
When I compile it and look at it’s declaration in the header,
T
is gone, and Swift will error if I try to create an
A
with a type parameter
I can see platform level classes have their type parameter specified, but I’m not sure why it is not generating this for my common module types.
r

russhwolf

10/29/2018, 6:33 PM
Swift is not aware of Kotlin's generics because it passes through Objective-C which doesn't support them. But you should be able to use them in Kotlin/Native code running on iOS.
a

alex.hart

10/29/2018, 6:39 PM
Got it. So are things like Kotlin collections etc. special cased? Because I see that they basically extend the corresponding NS* class and provide types to them. Example:
Copy code
__attribute__((objc_runtime_name("KotlinMutableSet")))
__attribute__((swift_name("KotlinMutableSet")))
@interface SharedcodeMutableSet<ObjectType> : NSMutableSet<ObjectType>
@end;
g

gildor

10/30/2018, 1:58 AM
Yes, collections have special handling of generics and you can use them from Swift
a

alex.hart

10/30/2018, 1:50 PM
Ok, thanks for the input everyone 🙂
5 Views