Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

[SwiftPH + PADC Meetup - May 2019] Swift Kotlin Syntax Comparison

20 visualizaciones

Publicado el

[SwiftPH + PADC Meetup - May 2019] Swift Kotlin Syntax Comparison by Mark Kevin King

About the speaker:
Mark Kevin King (https://twitter.com/swiftymarks) is a guy who now works for himself and have partnerships with different companies. Born as an iOS developer but also does Android Development and Rails API. Workaholic? Yes! Trying hard to be a Sage developer. He has been developing mobile apps for more than 4 years now. One proud work to be released soon in the market is the Krispy Kreme App. Yum!

About SwiftPH:
SwiftPH and iOSCodersPH are the Apple Developer Communities in the Philippines. SwiftPH is responsible for our meetups and the iOSCodersPH is our slack group. Our community aims to bring all the iOS (and Apple) developer in the Philippines together to learn from one another and help our Apple developer ecosystem grow.

If you are interested, join us at https://meetup.com/swiftph. You can also reach out to us at swiftphofficial@gmail.com.


About Philippine Android Developer Community (PADC):
Philippine Android Developer Community is the Android developer community in the Philippines. (https://www.meetup.com/Philippine-Android-Developers-Community)

About the event:
Date: May 18, 2019
Venue: BeautyMNL, Philippines

More info here:
https://www.meetup.com/SwiftPH/events/261166657/

Publicado en: Tecnología
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

[SwiftPH + PADC Meetup - May 2019] Swift Kotlin Syntax Comparison

  1. 1. Swift + Kotlin Comparison
  2. 2. Outline • History • Basics • Playgrounds vs. Main function • Declaring functions • Single-expression function • Variable declarations • Nullable • String interpolations
  3. 3. Swift Language (History) • Introduced in 2014 • Upgraded to v1.2 in 2014 • Swift 2 • Swift 2.2 (Open Source) • Swift 3 - 2016 • Swift 4 - 2017 • Swift 5 - Now
  4. 4. Kotlin Language (History) • Introduced by Jetbrains 2011 • Kotlin v1.0 - Feb 2016 • 2017 - First class support for Kotlin in Android • Kotlin v1.2 - Sharing code between JVM and Javascript platforms • Kotlin v1.3 - October 2018 • Google I/0 2019 - Preferred language for Android App Developers
  5. 5. Swift Interactive • Playgrounds
  6. 6. Kotlin Interactive • Main Function • Kotlin Interactive Shell
  7. 7. Variable Declaration Kotlin var number = 42 Swift var number = 42
  8. 8. Variable Declaration (Constant) Kotlin val number = 42 Swift let number = 42
  9. 9. Variable Declaration (Global Constant) Kotlin const val number = 42 Swift let number = 42
  10. 10. Declaring Functions Kotlin fun functionName(param1: Type1, param2: Type2, paramN: TypeN): ReturnType { // Function contents goes here…… } Swift func functionName(param1: Type1, param2: Type2, paramN: TypeN) -> ReturnType { // Function contents goes here…… }
  11. 11. Nullable (New Concept) Kotlin var b: String? = “abc” b = null //ok print(b) Swift var b: String? = “abc” b = nil //ok print(b)
  12. 12. String interpolation Kotlin var b: String = “abc” print(“Letter $b”) // Letter abc Swift var b: String = “abc” print(“Letter (b)”) // Letter abc
  13. 13. Outline • Control Structures • If else • Iterations • Switch Statement
  14. 14. If Else (Single If) Kotlin // Traditional Usage var max = a if (a < b) max = b Swift // Traditional Usage var max = a if a < b { max = b }
  15. 15. If Else (Single If else) Kotlin var max: Int if (a > b) { max = b } else { max = b } Swift var max = a if a < b { max = b } else { max = b }
  16. 16. If Else Kotlin var max: Int if (a > b) { max = b } else { max = b } Swift var max = a if a < b { max = b } else { max = b }
  17. 17. If Else Kotlin var max: Int if (a > b) { max = b } else { max = b } Swift var max = a if a < b { max = b } else { max = b }
  18. 18. Fast Iterations Kotlin val names = arrayOf(“Mike”, “Matt”, “Kurt”, “Steffi”) for (name in names) { print(“Hello $name”) } Swift let names = [“Mike”, “Matt”, “Kurt”, “Steffi”] for name in names { print(“Hello (name”)) }
  19. 19. For Loops Kotlin for (i in 1..3) { println(i) } Swift for i in 1…10 { print(i) } Swift for i in 1..<10 { print(i) }
  20. 20. While Loops Kotlin while (condition) { statements } Swift while condition { statements } Swift while x < 10 { x = x + 1 } Kotlin while (x < 10) { x = x + 1 }
  21. 21. Do While Loops Swift do { } while condition Kotlin do { } while (condition)
  22. 22. Switch Statement Swift switch value { case value1: //statement case value2: //statement default: break } Kotlin when (value) { value1 -> //statement value2 -> //statement else -> { //statement } }
  23. 23. Outline • Collections • Hashes
  24. 24. Collections Kotlin val thresholds = intArrayOf(10, 20, 30, 40, 50) Swift let integers = [1, 2, 3, 4] let strings = [“one”, “two”, “three”, “four”] let doubles = [1.0, 2.0, 3.0, 4.0] let objects = [dog, cat, tiger]
  25. 25. Collections functions Swift collection.append(object) collection.remove(at: Int) collection[x] = newValue //can only be done if not constant println("Average: ${thresholds.average()}") println(Max: ${thresholds.max()}") println("Sum: ${thresholds.sum()}") println("Count: ${thresholds.count()}") println("Size: ${thresholds.size}") println("First: ${thresholds.first()}") println("Last: ${thresholds.last()}") println("Index: ${thresholds[0]} == ${thresholds.get(0)}") println("Slice: ${thresholds.sliceArray(1..3) .toHashSet() .toString()}") thresholds = thresholds.plus("2")
  26. 26. Hashes Kotlin var dictionary: HashMap<String, String> = hashMapOf(“JFK” to “John Kennedy Interational Airport”) print(dictionary[“JFK”]) // “John Kennedy International Airport” Swift var dictionary = [String: String]() dictionary = [“JFK”: “John Kennedy International Airport”] print(dictionary[“JFK”]) // “John Kennedy International Airport”
  27. 27. Outline • Classes • Constructor • Inheritance • Lazy variables • Data Classes • Singletons
  28. 28. Classes • Classes • Constructor • Inheritance • Lazy variables • Singletons
  29. 29. Class Kotlin class Dog { } Swift class Dog { }
  30. 30. Constructor (Kotlin) Kotlin (Primary) Kotlin (Secondary) class Dog (breed: String){ constructor(){ } } Kotlin class Dog (breed: String){ }
  31. 31. Constructor (Swift) class Dog { let name: String let kind: String init(name: String, kind: String) { self.name = name self.kind = kind } }
  32. 32. Inheritance Swift class Dog: Pet { let name: String let kind: String init(name: String, kind: String) { self.name = name self.kind = kind } } Kotlin class Dog: Pet { constructor(name:String){ super.name = name } }
  33. 33. Lazy Variables Swift class Person { let firstName: String let lastName: String var fullName: String { return “(firstName) + (lastName)” } init(firstName: String, lastName: String) { self.firstName = firstName self.lastName = lastName } } class Person(_firstname: String, _lastname:String) { var firstName: String var lastName: String init{ firstName = _firstname lastName = _lastname } val fullName: String by lazy{ "$firstName $lastName"
  34. 34. Singletons Swift class LocationManager { static let shared = LocationManager() init() { //Optional do what ever needed } } Kotlin object LocationManager { init { //Do What ever needed
 } }
  35. 35. Extension Functions Swift extension Type { // New functionalities goes here func doSomething() { } } Kotlin class Type { } func Type.doSomething() { }
  36. 36. Outline • Protocols or Interfaces • Closures or Lambda
  37. 37. Protocols or Interfaces Swift protocol Animal { var canFly: Bool {get} func eat() func makeSound() } Kotlin interface Person { var canFly: Boolean fun eat() fun makeSound() }
  38. 38. Closures Swift func animate(completion: @escaping() -> Void) object.animate { Void in // Do something }
  39. 39. Lambda Kotlin fun animate(completion: (): Void) object.animate( { //Do something })

×