Share
Embed
Transcript
39 slides
-
Agenda New technologies in tooling for Kotlin/Native Memory model and
concurrency in Kotlin/Native 2 -
Kotlin Multiplatform Mobile Shared.framework ⌨ New code ⏳ Build project
8 Problems of an iOS-developer -
Kotlin Multiplatform Mobile 9 class MyClass { fun hello() =
"Hello from Kotlin!" } let a = MyClass() Problems of an iOS-developer -
Kotlin Multiplatform Mobile 10 / / . . . _
_ attribute __ ((swift_name("KotlinDouble"))) @interface KNFDouble : KNFNumber - (instancetype)initWithDouble:(double)value; + (instancetype)numberWithDouble:(double)value; @end; _ _ attribute __ ((swift_name("KotlinBoolean"))) @interface KNFBoolean : KNFNumber - (instancetype)initWithBool:(BOOL)value; + (instancetype)numberWithBool:(BOOL)value; @end; _ _ attribute __ ((objc_subclassing_restricted)) _ _ attribute __ ((swift_name("MyClass"))) @interface KNFMyClass : KNFBase - (instancetype)init _ _ attribute __ ((swift_name("init()"))) __ attribute __ ((objc_designated_initializer)); + (instancetype)new __ attribute _ _ ((availability(swift, unavailable, message="use object initializers instead"))); - (NSString *)hello __ attribute _ _ ((swift_name("hello()"))); @end; Problems of an iOS-developer -
Kotlin Multiplatform Mobile 12 • Lack of Swift and Obj-C
support in Android Studio • Necessity to rebuild the framework every time you change the interface • Complicated relation between declaration in Kotlin and usage in Swift Problems of an iOS-developer -
Kotlin/Native plugin for AppCode 2018 The fi rst release Development
on Kotlin/Native in AppCode Highlighting, autocompletion Run | Debug iOS Integration with a wizard 14 -
What is a symbol Symbol • Name • Location •
Attributes • Relations with other symbols • … 18 Internal representation of the declaration of anything in the code. Symbol tables - the IDE's knowledge of classes, functions, variables, etc. -
class Person { let name = "John" let surname =
"Doe" let age = 42 // Very important function func greet() { print("Hi \(name)!") } } class Person let name: String let surname: String let age: Int func greet() -> Void Symbol table 19 What is a symbol -
Obj-C - Swift Cross Resolve Obj-C class AnotherObject: NSObject @interface
AnotherObject : NSObject //... @end Naming Rules 20 -
MyShared.framework MyFramework.h MyFramework IDE Old approach val helloString = "Hello
from Kotlin!" @property (readonly) NSString *helloString; objc var helloString: String { get } Kotlin compiler ⏳ Build project 23 Symbols translation -
Kotlin compiler 24 Kotlin frontend Kotlin/Native backend Kotlin Code
Module Descriptors MyShared.framework MyFramework.h MyFramework Symbols translation -
Kotlin/Native backend 25 Module Descriptors MyShared.framework MyFramework.h MyFramework Obj-C Symbol
Structures Obj-C Symbols Swift Symbols Symbols translation -
IDE New approach val helloString = "Hello from Kotlin!" var
helloString: String { get } Internal Compiler Structures @property (readonly) NSString *helloString; objc New 26 Symbols translation -
Advantages of the new approach 🚀 Updates on the fl
y 🎯 Go to Declaration, refactorings and etc. 😅 Forgives mistakes 27 Symbols translation -
Hooray! Now you don't have to rebuild the framework
after each Kotlin code change! 28 print(a.hello) SourceKit -
Getting annotations from SourceKit What is SourceKit SourceKit request response
Navigation Highlighting Autocompletion … 29 -
30 val helloString = "Hello!" Create property SourceKit import MyFramework
Open Swift fi le Getting annotations from SourceKit Problem -
31 Open Swift usage print(a.hello) val hello = "Hello!" Rename
val helloString = "Hello!" Create property print(a.helloString) Use in Swift @property (readonly) NSString *helloString; MyFramework.h Build SourceKit Getting annotations from SourceKit Problem -
32 📁 MyFramework.framework/ 📁 Headers/ MyFramework.h 📁 Modules/ module.modulemap Info.plist
MyFramework SourceKit Getting annotations from SourceKit Solution -
33 📁 MyFramework.framework/ 📁 Headers/ MyFramework.h 📁 Modules/ module.modulemap SourceKit
After each Kotlin code change ~/Library/Caches/…/DerivedData/MyApp-byxnfgfeahmhpthjejgycztlpstg/SourceKitFrameworkStubs/MyFramework.framework Getting annotations from SourceKit Solution -
Optimizations 34 • Generate right before the opening of a
Swift fi le • Ignore changes in comments and function bodies / / This is very important fun doImportantThings(): Int { val a = 1 val b = 2 return a + b } Getting annotations from SourceKit -
Conclusions 36 In the future, Kotlin Multiplatform will become increasingly
friendly to iOS developers -
37 Cross-resolve between Kotlin and Swift already exists, and you
can try it right now in Kotlin/Native plugin for AppCode Conclusions -
38 In the KMP world, it is very useful to
know Gradle, even if you develop iOS apps Conclusions -
Thank you! 39 What we talked about: • KMP intro
• Current problems of the iOS world • Kotlin/Native plugin for AppCode • How Kotlin-Swift cross-resolve works • SourceKit problem and how it’s solved • Conclusions @appcode @aydarmukh