[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/
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
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())
12. Garbage Collection
Concurrent Mark Sweep
Automatic Reference
Counting
var person = Person("Marco", "Valmores")
var newperson = person
person = Person()
newperson = Person()
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. [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)
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]} ")
}
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. 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. Ranges
for (character in 'a'..'k')
print("$character ")
(1..5).forEach(::println)
(1..5).reversed().forEach {
counter -> print("$counter ")
}
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. 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. override fun toString() : String {
var result : String = ""
for(item : Item in items){
result += "${item.name} tttt
${item.cost} n"
}
return result
}
Functions