Support exposing Kotlin methods as Objective-C actions and outlets
This commit is contained in:
committed by
SvyatoslavScherbina
parent
2f30c15b45
commit
5a7e3e20b4
@@ -62,7 +62,11 @@ inline fun <T : ObjCObject?> interpretObjCPointerOrNull(rawPtr: NativePtr): T? =
|
||||
null
|
||||
}
|
||||
|
||||
inline fun <T : ObjCObject?> interpretObjCPointer(rawPtr: NativePtr): T? = interpretObjCPointerOrNull<T>(rawPtr)!!
|
||||
inline fun <T : ObjCObject> interpretObjCPointer(rawPtr: NativePtr): T = if (rawPtr != nativeNullPtr) {
|
||||
ObjCPointerHolder(rawPtr).uncheckedCast<T>()
|
||||
} else {
|
||||
throw NullPointerException()
|
||||
}
|
||||
|
||||
inline val ObjCObject.rawPtr: NativePtr get() = (this.uncheckedCast<ObjCPointerHolder>()).rawPtr
|
||||
inline val ObjCObject?.rawPtr: NativePtr get() = if (this != null) {
|
||||
@@ -105,6 +109,10 @@ annotation class ObjCConstructor(val initSelector: String)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class InteropStubs()
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
private annotation class ObjCMethodImp(val selector: String, val encoding: String)
|
||||
|
||||
@konan.internal.ExportForCompiler
|
||||
private fun <T : ObjCObject> allocObjCObject(clazz: NativePtr): T {
|
||||
val rawResult = objc_allocWithZone(clazz)
|
||||
|
||||
@@ -28,4 +28,20 @@ inline fun <R> autoreleasepool(block: () -> R): R {
|
||||
// TODO: null checks
|
||||
var <T : ObjCObject?> ObjCObjectVar<T>.value: T
|
||||
get() = interpretObjCPointerOrNull<T>(nativeMemUtils.getNativePtr(this)).uncheckedCast<T>()
|
||||
set(value) = nativeMemUtils.putNativePtr(this, value.rawPtr)
|
||||
set(value) = nativeMemUtils.putNativePtr(this, value.rawPtr)
|
||||
|
||||
/**
|
||||
* Makes Kotlin method in Objective-C class accessible through Objective-C dispatch
|
||||
* to be used as action sent by control in UIKit or AppKit.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class ObjCAction
|
||||
|
||||
/**
|
||||
* Makes Kotlin property in Objective-C class settable through Objective-C dispatch
|
||||
* to be used as IB outlet.
|
||||
*/
|
||||
@Target(AnnotationTarget.PROPERTY)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class ObjCOutlet
|
||||
|
||||
Reference in New Issue
Block a user