如何在 Kotlin/Native 中使用 CPointer

Jev*_*n54 6 ios kotlin-native kotlin-multiplatform

我不知道如何在 Kotlin/Native 中使用 CPointer;在我的 iOS 源代码集中,我需要构建与以下 Object-c 代码等效的 Kotlin(仅包括代码的相关部分):

    //Object-C copyItemAtPath
    NSError* error=nil;
    [[NSFileManager defaultManager]copyItemAtPath:srcPath toPath:dstPath error:&error ];
    if (error!=nil) {
        NSLog(@"%@", error);
    }
Run Code Online (Sandbox Code Playgroud)

但是在Kotlin/Native中,我不知道如何转换代码;我尝试了以下kotlin代码但失败了;

        //I try to read error info 
        val errorPtr = allocPointerTo<ObjCObjectVar<NSError?>>()
        NSFileManager.defaultManager.copyItemAtPath("source", target,errorPtr.value)
        Napier.e("[KNDraftCopy]${errorPtr.pointed?.value?.localizedDescription}")//null
        Napier.e("[KNDraftCopy]${errorPtr.pointed?.value}")//null
        Napier.e("[KNDraftCopy]${errorPtr.pointed}")//null
        Napier.e("[KNDraftCopy]${errorPtr}")//kotlinx.cinterop.NativePointed@d063d3a8
Run Code Online (Sandbox Code Playgroud)

我是 C 代码的鱼,我有一个问题:如何将我的 Obj-C 代码转换为 kotlin/native?我的方法对吗?(结果无效。)

// the function definition
fun copyItemAtPath(srcPath: kotlin.String, toPath: kotlin.String, error:CPointer<ObjCObjectVar<platform.Foundation.NSError?>>?)
Run Code Online (Sandbox Code Playgroud)