Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
iOSアプリ開発者から見たKotlin
Search
Koichiro Oishi
June 29, 2017
Programming
2
690
iOSアプリ開発者から見たKotlin
2017/06/29
第6回Kotlin勉強会 @ Sansan
Koishi
Koichiro Oishi
June 29, 2017
Tweet
Share
More Decks by Koichiro Oishi
See All by Koichiro Oishi
アプリのユニットテストについて初歩から考えてみる/ABC UnitTest
koishi
3
790
Kotlin/Swift 有理数クラスのすすめ
koishi
0
1.2k
5分でわかるPassword_Autofill_for_Apps
koishi
0
1k
Other Decks in Programming
See All in Programming
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
500
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
240
Identifying User Idenity
moro
6
8.4k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
460
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
400
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.2k
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.4k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
660
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.1k
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
140
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
Happy Clients
brianwarren
97
6.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
107
49k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Making Projects Easy
brettharned
115
5.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
14
2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
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