Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
iOSアプリ開発者から見たKotlin
Search
Koichiro Oishi
June 29, 2017
Programming
750
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
iOSアプリ開発者から見たKotlin
2017/06/29
第6回Kotlin勉強会 @ Sansan
Koishi
Koichiro Oishi
June 29, 2017
More Decks by Koichiro Oishi
See All by Koichiro Oishi
気がついたら子供が社会人になって 自分と同じモバイルアプリエンジニアになった件 / Parent-Child Engineers
koishi
0
710
アプリのユニットテストについて初歩から考えてみる/ABC UnitTest
koishi
3
940
Kotlin/Swift 有理数クラスのすすめ
koishi
0
1.4k
5分でわかるPassword_Autofill_for_Apps
koishi
0
1.2k
Other Decks in Programming
See All in Programming
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
phperだってパンチカードでコーディングしたい
o0h
PRO
0
350
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
Workers Cache を知る
syumai
0
370
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
250
sbt 2.0: takeoff
eed3si9n
0
160
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
0
110
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
970
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
Featured
See All Featured
Deep Space Network (abreviated)
tonyrice
0
370
How GitHub (no longer) Works
holman
316
150k
WENDY [Excerpt]
tessaabrams
14
40k
Docker and Python
trallard
47
4.2k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
The browser strikes back
jonoalderson
0
1.8k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Making Projects Easy
brettharned
120
6.8k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Transcript
iOSΞϓϦ։ൃऀ͔Βݟͨ Kotlin 2017/06/29 ୈ6ճKotlinษڧձ ˏ Sansan Koishi Koichiro Oishi, 2017/6/29
1
ࣗݾհ େੴ ߂Ұ γεςϜɾΞφϥΠζגࣜձࣾ iOSΞϓϦ։ൃऀ ΞΧϯτؔ࿈ * @mego_ * koishi
Koichiro Oishi, 2017/6/29 2
ίϯςΩετ iOSΞϓϦΤϯδχΞͰ͢ɻ Objective-CͱSwiftࣝ͋Δ(͋Δఔ) JavaͳΜͱͳͬͯ͘Δɻ Kotlin໊લͱͳΜͱͳ͘Γ্͕ΓΛɻ Koichiro Oishi, 2017/6/29 3
Kotlin͔Θ͍͍ ͱ͍͏͜ͱΛઌͷษڧձͰΓ·ͨ͠ Koichiro Oishi, 2017/6/29 4
ͦͯ͠ SwiftͱࣅͯΔ ͱ͍͏͜ͱᷚͰΓ·ͨ͠ Koichiro Oishi, 2017/6/29 5
ຊͦΜͳϨϕϧͰݟͨ KotlinͱSwiftͷҧ͍Λ ൃද͖ͤͯ͞·͢ɻ Koichiro Oishi, 2017/6/29 6
ࢀߟจݙ Swift ࣮ફೖ ஶऀͷ1ਓɺੴ͞Μ͔ΒαΠ ϯΒ͍·ͨ͠ɻ Koichiro Oishi, 2017/6/29 7
ࢀߟจݙ Kotlin ελʔτϒοΫ ௨শʮ͜ຊʯ ஶऀͷͨΖ͏͞Μ͔ΒαΠϯ Β͍·ͨ͠ɻ Koichiro Oishi, 2017/6/29 8
ࢀߟจݙ ೖ·Ͱͷ Kotlin ॿಡຊ ࢲʹͱͬͯྑͦ͞͏Ͱ͢ ͪ͜ΒΛϕʔεʹSwiftͱൺֱ ͍͖ͯ͠·͢ Koichiro Oishi, 2017/6/29
9
ຊͰ͢ɻ Koichiro Oishi, 2017/6/29 10
ΞδΣϯμ • جຊจ๏(ͬ͘͟Γ) • Null҆શ • ؔ, ΦϒδΣΫτ(γϯάϧτϯ), ίϯύχΦϯΦϒδΣΫτ(static) •
σʔλΫϥε • Extension(֦ுؔɺ֦ுϓϩύςΟ) Koichiro Oishi, 2017/6/29 11
͜ͷ͋ͨΓΛKotlinͱSwift Ͱൺֱͯ͠Έ·͢ Koichiro Oishi, 2017/6/29 12
جຊจ๏ - มͷએݴ1 Kotlin val num : Int = 1
var num2 : Int = 2 Swift let num: Int = 1 var num2: Int = 2 valͱletఆ 1 Kotlinॿಡຊ p.28 Koichiro Oishi, 2017/6/29 13
جຊจ๏ - มͷએݴ Kotlin val num = 1 var num2
= 2 Swift let num = 1 var num2 = 2 ܕͷলུ(ܕਪ) Koichiro Oishi, 2017/6/29 14
جຊจ๏ - whenࣜ2 Kotlin val value = 1 val str
= when(value) { 1-> "one" 2-> "two" else -> "other" } 2 Kotlinॿಡຊ p.30 Koichiro Oishi, 2017/6/29 15
جຊจ๏ - whenࣜ Swift let value = 1 let str
= { switch value { case 1: "one" case 2: "two" default: "other" } } Koichiro Oishi, 2017/6/29 16
Null҆શ - Nullෆڐ༰ܕ3 Kotlin var a: String = "abc" a
= null // => ίϯύΠϧΤϥʔ Swift var a: String = "abc" a = nil // => ίϯύΠϧΤϥʔ 3 Kotlinॿಡຊ p.33 Koichiro Oishi, 2017/6/29 17
Null҆શ - Nullڐ༰ܕ Kotlin var b: String? = "abc" b
= null // => OK Swift var b: String? = "abc" b = nil // => OK Koichiro Oishi, 2017/6/29 18
Null҆શ - Null νΣοΫͱ҆શͳݺͼग़͠ Kotlin Null ෆڐ༰ܕͷࢀর var a: String
= "abc" val l : Int = a.length // => OK Null ڐ༰ܕͷࢀর var b: String? = "abc" val l : Int = b.length // => ίϯύΠϧΤϥʔ Koichiro Oishi, 2017/6/29 19
Null҆શ - Null ڐ༰ܕͷϝιουݺͼग़͠ Kotlin Null ෆڐ༰ܕͷࢀর var b: String?
= "abc" val l : Int = if(b != null) b.length else -1 Null ڐ༰ܕͷࢀর val l : Int? = b?.length Koichiro Oishi, 2017/6/29 20
Null҆શ - Null ڐ༰ܕͷϝιουݺͼग़͠ Swift Null ෆڐ༰ܕͷࢀর var b: String?
= "abc" let l: Int = b?.characters.count ?? -1 Null ڐ༰ܕͷࢀর let l: Int? = b?.characters.count Koichiro Oishi, 2017/6/29 21
Null҆શ - ΤϧϏεԋࢉࢠ Kotlin val l: Int = b?.length ?:
-1 Swift let l: Int = b?.characters.count ?? -1 Koichiro Oishi, 2017/6/29 22
Null҆શ - !!ԋࢉࢠ Kotlin val l: Int = b!!.length b͕Null(nil)ͩͬͨΒ
KotlinͰNullPointerException͕ൃੜ Koichiro Oishi, 2017/6/29 23
Null҆શ - !!ԋࢉࢠ Swift let l: Int = b!.characters.count ڧ੍Ξϯϥοϓ
b͕Null(nil)ͩͬͨΒ SwiftͰΫϥογϡ͠·͢ Koichiro Oishi, 2017/6/29 24
Null҆શ - Swiftͷ߹ if let count = b?.characters.count { print(count)
//ඇoptionalܕ } if letͷϒϩοΫͰNullෆڐ༰ܕ(ඇoptionalܕ) ͱͯ͑͠Δ Koichiro Oishi, 2017/6/29 25
Null҆શ - Swiftͷ߹ guard let count = b?.characters.count else {
return } print(count) //ඇoptionalܕ guardจҎ߱ͰNullෆڐ༰ܕ(ඇoptionalܕ)ͱ͠ ͯ͑Δ Koichiro Oishi, 2017/6/29 26
ؔ4 Kotlin fun add(x: Int, y: Int): Int { return
x + y } Swift func add(x: Int, y: Int) -> Int { return x + y } 4 Kotlinॿಡຊ p.36 Koichiro Oishi, 2017/6/29 27
ΦϒδΣΫτ(γϯάϧτϯ)5 Kotlin ఆٛ object DataProviderManager { fun registerDataProvider(provider: DataProvider) {
// ... } } ݺͼग़͠ DataProviderManager.registerDataProvider(...) 5 Kotlinॿಡຊ p.47 Koichiro Oishi, 2017/6/29 28
ΦϒδΣΫτ(γϯάϧτϯ) Swift ఆٛ class DataProviderManager { static let sharedInstance =
DataProviderManager() private init() { ... } func registerDataProvider(provider: DataProvider) { } } ݺͼग़͠ DataProviderManager.sharedInstance.registerDataProvider(...) Koichiro Oishi, 2017/6/29 29
ίϯύχΦϯΦϒδΣΫτ(static) Kotlin ఆٛ class MyClass { companion object Factory {
fun create(): MyClass = MyClass() } } ݺͼग़͠ val instance = MyClass.create() Koichiro Oishi, 2017/6/29 30
ίϯύχΦϯΦϒδΣΫτ(static) Swift ఆٛ class MyClass { static func create() ->
MyClass { return MyClass() } } ݺͼग़͠ let test = MyClass.create() Koichiro Oishi, 2017/6/29 31
σʔλΫϥε6 Kotlin data class Person(val id: Long, var name: String)
KotlinʹPairTripleͳͲ͋Δ͕ɺ ม໊͚ͭΒΕͳ͍ͬΆ͍ Swift typealias Person = (id: Int, name: String) σʔλΫϥε = શʹSwiftͷλϓϧͰͳ͘ SwiftͷStructͬΆ͋͞Δʁ 6 Kotlinॿಡຊ p.52 Koichiro Oishi, 2017/6/29 32
Extension - ֦ுؔ(Extension Function)7 Kotlin fun String.appendBeer() : String =
"${this}beer!" println("I like".appendBeer()) // => I like beer! Swift extension String { func appendBeer() -> String { return "\(self)beer!" } } print("I like".appendBeer()) 7 Kotlinॿಡຊ p.55 Koichiro Oishi, 2017/6/29 33
Extension - ֦ுϓϩύςΟ(Extension Properties) Kotlin ఆٛ val <T> List<T>.lastIndex: Int
get() = size - 1 ݺͼग़͠ val arr = listOf(1,2,3) println(arr.lastIndex) //=> 2 Koichiro Oishi, 2017/6/29 34
Extension - ֦ுϓϩύςΟ(Extension Properties) Swift ఆٛ extension Array { var
lastIndex: Int { return self.count - 1 } } ݺͼग़͠ let arr = [1,2,3] print(arr.lastIndex) //=> 2 Koichiro Oishi, 2017/6/29 35
ࠓճ͜͜·ͰͰ͕͢ɺ ͜Ε͔ΒKotlin͍͖ͬͯ·͢ ߴ֊ؔɾϥϜμɾΞΫηε੍ݶ͋ͨΓ औΓ্͔͛ͨͬͨͷͰ͕͢ϘϦϡʔϜతʹ… Koichiro Oishi, 2017/6/29 36
SwiftΛ͋·Γ͝ଘͳ͍ํɺ ͍͔͕Ͱͨ͠Ͱ͠ΐ͏͔ Koichiro Oishi, 2017/6/29 37
Swift ͔Θ͍͍ͷͰ? ͱݴͬͯΈ͔ͨͬͨͷͰ͢ Koichiro Oishi, 2017/6/29 38
࠷ޙʹ Kotlinͷ͕͜͜ྑ͍ ͱ͔ڭ͍͑ͯͩ͘͞ʂ Koichiro Oishi, 2017/6/29 39
ͪͳΈʹ ͜ͷαΠτͰKotlinͱSwiftͷҧ ͍͕·ͱ·ͬͯ·͢Ͷɻ Swift is like Kotlin http://nilhcem.com/swift-is- like-kotlin/ Koichiro
Oishi, 2017/6/29 40
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ Koichiro Oishi, 2017/6/29 41