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 Feature Comparison

7 visualizaciones

Publicado el

[SwiftPH + PADC Meetup - May 2019] Swift Kotlin Feature Comparison by Mac Valmores

About the speaker:
Currently leading, PADC and KotlinPH. A lead mobile developer in TEravibe Inc. addicted to board games.

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 Feature Comparison

  1. 1. Comparison
  2. 2. • NO ‘;’ • Filename does not need to be Class name • main runnable does need to be in a Class • Super Class is “ANY” like Object • All classes are final • guards Kotlin x Swift
  3. 3. DataTypes int Int toByte(): Byte toShort(): Short toInt(): Int toLong(): Long toFloat(): Float toDouble(): Double toChar(): Char Type conversion
  4. 4. Permissions info.plist Manifest.xml Code
  5. 5. Interoperability JS, C, JAVAC#
  6. 6. ReferenceTypes var person = Person("Marco", "Valmores") println(">> " + person.fullName) var newperson = person newperson.firstName = "Koin" print(">> $person.firstName == $newperson.firstName)
  7. 7. Layout Interface builder xml
  8. 8. Threading let queue = DispatchQueue(label : “current queue”) queue.async{ self.doWork() } DispatchQueue.main.async{ self.view.backgroundColor = .black }
  9. 9. Threading val c = AtomicLong() for (i in 1..1_000_000L) thread(start = true) { c.addAndGet(i) } println(c.get()) val c = AtomicLong() for (i in 1..1_000_000L) GlobalScope.launch { c.addAndGet(i) } println(c.get())
  10. 10. Layouts None xml
  11. 11. Context None Automatic Reference Counting
  12. 12. Garbage Collection Concurrent Mark Sweep Automatic Reference Counting var person = Person("Marco", "Valmores") var newperson = person person = Person() newperson = Person()
  13. 13. Dependency Management Gems Carthage Gradle
  14. 14. Thank you
  15. 15. History 2014 Introduced 2016 Swift 3 2017 Swift 4 2018 Swift 5
  16. 16. History 2011 Introduced 2014 Introduced to Android 2016 Class Support for Android Sharing code for JVM and JS 2018 Kotlin 1.3 2019 Preferred Language for Android
  17. 17. IDE Integrated Development Environment
  18. 18. • NO ‘;’ • Filename does not need to be Class name • main runnable does need to be in a Class • Super Class is “ANY” like Object Primer fun main(args : Array<String>) { }
  19. 19. [val var const] variable name : [data type] = value Variables val var const single assignment multiple assignment Compile-Time Constants val MILLION = 1_000_000 var cost : Float = 10.99f var hex : Hexadecimals = 0xFF_12_34_AB val input: String? print("Enter something: ") input = readLine() print (input)
  20. 20. Variables toByte(): Byte toShort(): Short toInt(): Int toLong(): Long toFloat(): Float toDouble(): Double toChar(): Char val truth : Boolean? = null
  21. 21. Variables : Strings val text = """ |The quick brown fox |jumped over the fence. """.trimMargin()
  22. 22. Collections : Array var products = Array<Item>(2){ Item() } var item = Item() item.name = "Motorola Razor" item.cost = 600.00 products[0] = item var discountItem = DiscountItem() discountItem.name = "Nokia 3310" discountItem.cost = 1000.0 products[1] = discountItem item = Item() item.name = "Smart Phone" item.cost = 1.0 products = products.plus(item) for(item in products){ println("${item.name} : ${item.cost}") }
  23. 23. val thresholds = intArrayOf(10, 20, 30, 40, 50) println("Average: ${thresholds.average()}") println("Max: ${thresholds.max()}") println("Count: ${thresholds.count()}") println("Size: ${thresholds.size}") println("Sum: ${thresholds.sum()}") println("First: ${thresholds.first()}") println("Last: ${thresholds.last()}") println("Index: ${thresholds[0]} == ${thresholds.get(0)}") println("Slice: ${thresholds.sliceArray(1..3) .toHashSet() .toString()}") Collections : Array
  24. 24. Collections : Array val it: Iterator<Int> = thresholds.iterator() while (it.hasNext()) { val e = it.next() print("$e ") } for (i in 0 until thresholds.size) { print("${thresholds[i]} ") }
  25. 25. Collections : Array val array = arrayOf(intArrayOf(1,2,3), intArrayOf(10,20,30)) println("Index : ${array[0][1]}")
  26. 26. Collections val products: ArrayList<Item> = ArrayList() val products = listOf<Item>() val products = setOf<Item>()
  27. 27. Looping val locationslist = listOf("Makati", "Manila", "Marikina") for (index in stores.indices) { println("item at $index is ${stores[index]}") } var index = 0 while (index < stores.size) { println("item at $index is ${stores[index]}") index++ } for(location : String in stores){ println("Location : $location") }
  28. 28. Ranges for (counter in 1..5) { print(x) } for (counter in 1..10 step 2) { print(x) } for (counter in 30 downTo 1) print("$counter ")
  29. 29. Ranges for (character in 'a'..'k') print("$character ") (1..5).forEach(::println) (1..5).reversed().forEach { counter -> print("$counter ") }
  30. 30. Functions fun printReceipt() { for(item : Item in items){ println("$item.name : ${item.Cost}") } } fun removeItem(itemToBeRemoved : Item) : Unit{ for(item : Item in items){ if (item.name.equals(itemToBeRemoved.name)){ } } }
  31. 31. fun totalTax(totalCost : Double) : Double = totalCost * tax; fun totalCost() : Double { var cost = 0.0 for(item : Item in items){ cost += item.cost } return cost } Functions
  32. 32. override fun toString() : String { var result : String = "" for(item : Item in items){ result += "${item.name} tttt ${item.cost} n" } return result } Functions
  33. 33. fun size() : Int?{ return items.size } Nullable
  34. 34. fun totalCost() : Double { var cost = 0.0 for(item : Item in items){ if(item is DiscountItem){ cost += item.cost - (item.cost * item.discount) }else { cost += item.cost } } return cost } Type Checking
  35. 35. Control Flow : when for (x in 0..100 step 2) { when(x % 2){ 0 -> println("Start : $x") is Int -> println("Number : $x") else -> print(".") } }
  36. 36. Control Flow : when fun totalCost() : Double { var cost = 0.0 for(item : Item in items){ when(item) { is DiscountItem -> cost += item.cost – item.cost * item.discount) is SalesItem -> cost += item.cost else -> cost= cost } } return cost }
  37. 37. Lambda val locationslist = listOf("Makati", "Manila", "Marikina“, "Caloocan", "Quezon", "Pasig") locationslist .filter { it.startsWith("M") } .sortedBy { it } .map { it.toUpperCase() } .forEach { println(it) }
  38. 38. Kotlin Interactive ClassesConstructorInheritanceLazy variablesData ClassesSingletons FunctionsFunction TypesFunction literalsExtensions Delegates or InterfacesClosures or Lambda Control StructuresIf elseIterationsSwitch Statement
  39. 39. HistoryBasicsPlaygrounds vs. Main functionDeclaring functionsSingle-expression functionVariable declarationsNullableString interpolations

×