Jacob Rhoda
06/19/2023, 8:41 PMNSError **
argument?Jeff Lockhart
06/21/2023, 4:24 PMmemScoped {
val error = alloc<ObjCObjectVar<NSError?>>()
val result = objcFun(params, error.ptr)
val nsError = error.value
if (nsError != null) {
// throw exception, return error type, etc.
}
// return result, success type, etc.
}
You can wrap this code in a reusable function that aligns with your app's error handling pattern.Jeff Lockhart
06/21/2023, 4:26 PMnil
on error, since Kotlin constructors can't have null
return types the interop header can't represent the constructor with a nullable type, and so it will throw a NullPointerException
when an error occurs. In this case I catch the NPE and handle the NSError
instead.Jacob Rhoda
06/21/2023, 9:53 PMJacob Rhoda
06/21/2023, 9:54 PMval nsError: NSError? = null
val errorPtr = ObjCObjectVar<NSError?>(nsError.objcPtr()).ptr
Jeff Lockhart
06/22/2023, 4:19 AMalloc<ObjCObjectVar<NSError?>>()
Jacob Rhoda
06/22/2023, 3:04 PMJacob Rhoda
06/22/2023, 3:07 PMJacob Rhoda
06/22/2023, 4:02 PMJeff Lockhart
06/22/2023, 4:13 PM