04/23/2023, 1:50 AM
I am creating a library by interoping with an objc framework. When using a class that generates Kotlin symbols like below, the constructor returns null and no value is placed in the error pointer, causing a kotlin.NullPointerException. I would like to retrieve the contents of NSError by having a value in the error pointer. Is there any way to do this?
generated interop symbol
@ExternalObjCClass public open class SomeObjCClass : NSObject {
  @ObjCConstructor public constructor(arg: String, error: CPointer<ObjCObjectVar<NSError?>>?) { /* compiled code */ }
  @ObjCConstructor public constructor() { /* compiled code */ }
  @Deprecated @ObjCMethod @ConsumesReceiver @ReturnsRetained public open external fun init(): SomeObjCClass? { /* compiled code */ }
  @Deprecated @ObjCMethod @ConsumesReceiver @ReturnsRetained public open external fun initArg(arg: String, error: CPointer<ObjCObjectVar<NSError?>>?): SomeObjCClass? { /* compiled code */ }
objc header
@interface SomeObjCClass : NSObject
- (instancetype)init NS_UNAVAILABLE;
- (nullable instancetype)initWithArg:(NSString *)arg error:(NSError **)error;
I have given up on catching errors as NSError. As a somewhat rough workaround, I have decided to wrap the constructor with runCatching.