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

Liang Song

06/27/2019, 10:37 PM
Hi I am testing generics support for Objective-C/Swift in
1.3.40
, I have two interfaces
Copy code
interface CompletionHandler<T> {
    fun onCompletion(result: T)
    fun onException(exception: Exception)
}
Copy code
interface TestGenerics {
    fun test(completionHandler: CompletionHandler<String>)
}
the signature of
TestGenerics
in the generated Objective-C header is
Copy code
__attribute__((swift_name("TestGenerics")))
@protocol TMDTestGenerics
@required
- (void)testCompletionHandler:(id<TMDCompletionHandler>)completionHandler __attribute__((swift_name("test(completionHandler:)")));
@end;
Looks like it is still not supported
b

basher

06/27/2019, 11:03 PM
Obj-C doesn't have support for generics in protocols
In Obj-C, you can only have generic classes
l

Liang Song

06/27/2019, 11:14 PM
Hi, yes you are right, if I change the
CompletionHandler
to a class,
Copy code
typealias OnCompletion<T> = (result: T) -> Unit
typealias OnException = (exception: Exception) -> Unit
class CompletionHandler<T>(val onCompletion: OnCompletion<T>, val onException: OnException)
the signature of
TestGenerics
in the generated Objective-C header
Copy code
__attribute__((swift_name("TestGenerics")))
@protocol TMDTestGenerics
@required
- (void)testCompletionHandler:(TMDCompletionHandler<NSString *> *)completionHandler __attribute__((swift_name("test(completionHandler:)")));
@end;
r

ribesg

06/28/2019, 7:24 AM
Make sure you set the compiler parameter to enable generics