Piasy
01/09/2020, 11:52 AMViewController.m
) calls iOS kotlin function (KmppBootstrap.test
, built to iOS static library), which accept an ObjC object (IOSDummyObj
from IOSDummyFramework.framework
), if KmppBootstrap.test
use IOSDummyObj
, my app will crash at Kotlin_Interop_refToObjC
with EXC_BAD_ACCESS (code=1, address=0x1a102ba0120)
, but if KmppBootstrap.test
don't, my app runs fine.
Could you guys please help me, thanks!
I upload my repro project onto GitHub, in the ios_static_lib_repro
branch of https://github.com/Piasy/KmppBootstrap , my iOS kotlin code is mainly kmpp/src/iosMain/kotlin/com/piasy/kmpp/KmppBootstrap.kt
, and iOS app is under iOSExample2/iOSExample2/ViewController.m
.
Or maybe my app code is wrong?
IOSDummyObj* obj = [[IOSDummyObj alloc] initWithInt:42];
libkmpp_ExportedSymbols* lib = libkmpp_symbols();
libkmpp_kref_com_piasy_kmpp_KmppBootstrap kmpp = lib-><http://kotlin.root.com|kotlin.root.com>.piasy.kmpp.KmppBootstrap.KmppBootstrap();
libkmpp_kref_Dummy_IOSDummyObj dummy;
dummy.pinned = (__bridge libkmpp_KNativePtr)(obj);
lib-><http://kotlin.root.com|kotlin.root.com>.piasy.kmpp.KmppBootstrap.test(kmpp, dummy);
Artyom Degtyarev [JB]
01/10/2020, 1:41 PMPiasy
01/10/2020, 1:49 PMiOSExample2.xcodeproj
under iOSExample2
folder, sorry that it was ignored, I just commit it.
Then after you run it in iPhone device, it would crash.
If you change kotlin code, then you need run ./gradlew :kmpp:linkDebugStaticIos && cp kmpp/build/bin/ios/debugStatic/libkmpp.a libs/iOS/ && cp kmpp/build/bin/ios/debugStatic/libkmpp_api.h libs/iOS/
.Artyom Degtyarev [JB]
01/13/2020, 8:48 AMPiasy
01/13/2020, 8:48 AMcreateIOSDummyObj
, and call it from ObjC?Artyom Degtyarev [JB]
01/13/2020, 11:39 AMPiasy
01/13/2020, 11:50 AMDummyObjWithMap
) which need a NSDictionary*
to init, so I create a kotlin wrapper function (let's call it createDummyObjWithMap
) to create it, which require a kotlin Map
. I can write kotlin code without any question, but in the generated header, createDummyObjWithMap
require a libkmpp_kref_kotlin_collections_Map
, how could I convert my ObjC NSDictionary*
to libkmpp_kref_kotlin_collections_Map
?Artyom Degtyarev [JB]
01/14/2020, 9:03 AMIOSDummyObj(dict: NSDictionary)
constructor, I’ve made a wrapper like:
fun wrappedInit(dict: CPointer<*>){
IOSDummyObj(interpretObjCPointer<NSDictionary>(dict.rawValue)))
}
and called it from Objective-C as
NSDictionary* dict = [NSDictionary alloc];
dict = @{ @“firstInt” : @2,
@“secondInt” : @2,
};
lib-><http://kotlin.root.com|kotlin.root.com>.piasy.kmpp.KmppBootstrap.wrappedInit(kmpp, (__bridge void *)(dict));
I think it can be done even prettier, but I am no expert in this particular case 😅.Piasy
01/14/2020, 9:04 AMList<KtObj>
, in the generated header, it returns libkmpp_kref_kotlin_collections_List
, how could I iterate over it?Artyom Degtyarev [JB]
01/17/2020, 1:12 PMiterate
, I suppose. Nothing is exposed to the library API by default.Piasy
01/17/2020, 1:13 PM