Hello, newbie to native world.
What is the best way to handle obj c functions that throws an exception. Basically they carry an extra param with a type
CPointer<ObjCObjectVar>NSError?>>
.
Using try and catch is not useful and I don't want to pass in null
class NSErrorException(val nsError: NSError) : Exception(nsError.localizedDescription)
Copy code
inline fun <T> throwNSErrors(block: (CPointer<ObjCObjectVar<NSError?>>) -> T): T = memScoped {
val err = alloc<ObjCObjectVar<NSError?>>()
val result = block(err.ptr)
if (err.value != null) throw NSErrorException(err.value!!)
result
}
a
ayodele
04/18/2023, 5:38 PM
Thank you @Sam
ayodele
04/18/2023, 10:07 PM
@Sam do you know how to observe properties from Kotlin?? Like we can do from Swift with
addObserver
s
Sam
04/18/2023, 10:10 PM
Hmm... I'd need to see an example. I don't think I've ever used
addObserver
in Swift.
Sam
04/18/2023, 10:10 PM
It is worth noting that Kotlin uses Objective-C as a go-between with Swift. So some Swift-only APIs/idioms aren't directly available to Kotlin.