Ciaran Sloan
12/21/2022, 7:59 PMCiaran Sloan
12/21/2022, 7:59 PM// commonMain
expect interface MyCoolInterface
And the implementations look like this:
// androidMain
actual interface MyCoolInterface
// iosMain
actual typealias MyCoolInterface = MyCinteropProtocol
Neither MyCoolInterface
nor MyCinteropProtocol
is exported to the headers.
I've found this YouTrack issue which confirms that this is not yet supported. However, wondering if anyone has any suggestions for working around this?Ciaran Sloan
12/21/2022, 8:00 PMMyCoolInterface
as an interface
on iosMain (rather than a typealias) (fails with error Only classes are supported as subtypes of Objective-C types)
• Defining MyCoolInterface
as a class in all modules. (fails with error Kotlin implementation of Objective-C protocol must have Objective-C superclass (e.g. NSObject)Landry Norris
12/21/2022, 9:00 PMCiaran Sloan
12/22/2022, 9:43 AMMyLibrary
exposes the interface MyInterface
which can be implemented in the common code of a KMM application MyApp
. I'm also writing some swift utilities in a separate swift library SwiftUtils
which is dependant on the MyLibrary
framework, and uses MyInterface
for example:
class MySwiftClass {
func doWorkWith(_ object: MyInterface) {}
}
The issue I have is that the ObjC declaration of MyInterface
is slightly different in MyApp
(iOS) vs SwiftUtils
(iOS), I suspect due to how the frameworks are generated. (they have different prefixes).
So I'm trying to generate the interface in ObjC, then using cinterop add it to both the library and the swift utils. Hopefully this makes sense!Ciaran Sloan
12/22/2022, 10:05 AMCiaran Sloan
12/22/2022, 10:12 AMRick Clephas
12/22/2022, 10:29 AMRick Clephas
12/22/2022, 10:30 AM@ObjCName
annotation.Rick Clephas
12/22/2022, 10:31 AMCiaran Sloan
12/22/2022, 10:50 AM@ObjName
that might solve my problems 🤔Ciaran Sloan
12/22/2022, 10:53 AMSharedModuleNameProtocolName
(so long as i set transitiveExport = true
) but in the swift library its getting named LibraryNameProtocolName
. Hence I started looking into cinterop to get around thisRick Clephas
12/22/2022, 10:55 AMRick Clephas
12/22/2022, 10:58 AMKMMViewModelCoreObjC
declares a protocol (KMMVMViewModelScope
) which is used in Kotlin via cinterop and in the Swift library KMMViewModelCore
.Ciaran Sloan
12/22/2022, 10:58 AMCiaran Sloan
12/22/2022, 10:58 AMCiaran Sloan
12/22/2022, 10:59 AM@ObjCName
annotation coming up in 1.8 though!Rick Clephas
12/22/2022, 11:01 AM@HidesFromObjC
and @ShouldRefineInSwift
annotations)!Roberto Fernandez Montero
06/14/2023, 11:55 AMCiaran Sloan
06/19/2023, 10:02 AM