SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

En vedette

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
 

En vedette (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