SlideShare una empresa de Scribd logo
1 de 39
Comparison
• 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
DataTypes
int Int
toByte(): Byte
toShort(): Short
toInt(): Int
toLong(): Long
toFloat(): Float
toDouble(): Double
toChar(): Char
Type conversion
Permissions
info.plist Manifest.xml
Code
Interoperability
JS, C, JAVAC#
ReferenceTypes
var person = Person("Marco", "Valmores")
println(">> " + person.fullName)
var newperson = person
newperson.firstName = "Koin"
print(">> $person.firstName == $newperson.firstName)
Layout
Interface builder xml
Threading
let queue = DispatchQueue(label : “current queue”)
queue.async{
self.doWork()
}
DispatchQueue.main.async{
self.view.backgroundColor = .black
}
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())
Layouts
None xml
Context
None Automatic Reference
Counting
Garbage Collection
Concurrent Mark Sweep
Automatic Reference
Counting
var person = Person("Marco", "Valmores")
var newperson = person
person = Person()
newperson = Person()
Dependency Management
Gems
Carthage
Gradle
Thank you
History
2014
Introduced
2016
Swift 3
2017
Swift 4
2018
Swift 5
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
IDE
Integrated Development Environment
• 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>) {
}
[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)
Variables
toByte(): Byte
toShort(): Short
toInt(): Int
toLong(): Long
toFloat(): Float
toDouble(): Double
toChar(): Char
val truth : Boolean? = null
Variables : Strings
val text = """
|The quick brown fox
|jumped over the fence.
""".trimMargin()
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}")
}
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
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]} ")
}
Collections : Array
val array = arrayOf(intArrayOf(1,2,3),
intArrayOf(10,20,30))
println("Index : ${array[0][1]}")
Collections
val products: ArrayList<Item> = ArrayList()
val products = listOf<Item>()
val products = setOf<Item>()
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")
}
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 ")
Ranges
for (character in 'a'..'k')
print("$character ")
(1..5).forEach(::println)
(1..5).reversed().forEach {
counter -> print("$counter ")
}
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)){
}
}
}
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
override fun toString() : String {
var result : String = ""
for(item : Item in items){
result += "${item.name} tttt
${item.cost} n"
}
return result
}
Functions
fun size() : Int?{
return items.size
}
Nullable
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
Control Flow : when
for (x in 0..100 step 2) {
when(x % 2){
0 -> println("Start : $x")
is Int -> println("Number : $x")
else -> print(".")
}
}
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
}
Lambda
val locationslist
= listOf("Makati", "Manila", "Marikina“,
"Caloocan", "Quezon", "Pasig")
locationslist
.filter { it.startsWith("M") }
.sortedBy { it }
.map { it.toUpperCase() }
.forEach {
println(it)
}
Kotlin Interactive
ClassesConstructorInheritanceLazy
variablesData ClassesSingletons
FunctionsFunction TypesFunction
literalsExtensions
Delegates or InterfacesClosures or Lambda
Control StructuresIf elseIterationsSwitch
Statement
HistoryBasicsPlaygrounds vs. Main
functionDeclaring functionsSingle-expression
functionVariable declarationsNullableString
interpolations

Más contenido relacionado

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Destacado

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 

Destacado (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

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