dsgryazin
11/21/2017, 3:39 PMAppDelegate.h + AppDelegate.m files with stub implementation in @implementation AppDelegate
we also have AppDelegate.kt:
class AppDelegate : UIResponder(), UIApplicationDelegateProtocol
override fun init() = initBy(AppDelegate())
Please, correct my understandings in thread >dsgryazin
11/21/2017, 3:40 PMinitBy(AppDelegate()) - AppDelegate here is the stub declared in AppDelegate.m
2. what's the initBy fun? guess it's a kotlinx.cinterop.initBy but I don't understand where the receiver is.
@konan.internal.Intrinsic
external fun <T : ObjCObjectBase> T.initBy(constructorCall: T): T
3. Anyway, then you find initBy marker with
val objCObjectInitBy = packageScope.getContributedFunctions("initBy").single()
and use it in LLVM IR.
4. The ObjC AppDelegate declaration is needed because no straight Kotlin -> C interop is developed yet. Thus iOS can't easily call @protocol UIApplicationDelegate implemented in Kotlin. So you feed the ios with ObjC stub, but placing the kotlin implementation on LLVM level.Sam
11/21/2017, 8:43 PMdsgryazin
11/21/2017, 9:17 PMsvyatoslav.scherbina
11/22/2017, 8:44 AM4. The ObjC AppDelegate declaration is needed because no straight Kotlin -> C interop is developed yet. Thus iOS can’t easily callNo, straight Kotlin -> Objective-C interop is available, and iOS can call the protocol implemented in Kotlin. Objective-C stubs are required only to interact with Xcode. So:implemented in Kotlin. So you feed the ios with ObjC stub, but placing the kotlin implementation on LLVM level.@protocol UIApplicationDelegate
1.- AppDelegate here is the stub declared ininitBy(AppDelegate())AppDelegate.m
AppDelegate here is the class this code is located in.
what’s theThe receiver is the same as the receiver of thefun? guess it’s ainitBybut I don’t understand where the receiver is.kotlinx.cinterop.initBy
init method being implemented.
initBy is actually just an intrinsic to call the Kotlin constructor on allocated object instance. It is required because in Objective-C initializers are methods, which can be called virtually. So in some cases, e.g. when iOS allocates and initializes the user-provided class by itself, you need to override some init* methods. And initBy intrinsic allows to implement these methods by calling the corresponding Kotlin constructors.dsgryazin
11/22/2017, 8:51 AMsvyatoslav.scherbina
11/22/2017, 8:55 AM