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
Kotlinを使って思った10のコト fukuoka.kt #1
Search
chocomelonchan
July 05, 2017
Programming
0
530
Kotlinを使って思った10のコト fukuoka.kt #1
chocomelonchan
July 05, 2017
Tweet
Share
More Decks by chocomelonchan
See All by chocomelonchan
アプリを最速でリリースした話 #pixiv Night 4
chocomelonchan
4
4.3k
iOSとAndroidで共通のc++のコードを使いたいけど厳しかった話
chocomelonchan
0
1.6k
droidkaigi
chocomelonchan
6
24k
potatotips16
chocomelonchan
3
2.9k
誰も話たがらない話をしたい 翻訳リソース編
chocomelonchan
2
790
Other Decks in Programming
See All in Programming
qmuntal/stateless のススメ
sgash708
0
120
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
110
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
490
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
270
CSC305 Lecture 13
javiergs
PRO
0
130
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
CSC509 Lecture 09
javiergs
PRO
0
110
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
5
3.6k
Hotwire or React? ~Reactの録画機能をHotwireに置き換えて得られた知見~ / hotwire_or_react
harunatsujita
9
4.1k
Macとオーディオ再生 2024/11/02
yusukeito
0
210
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
Featured
See All Featured
Speed Design
sergeychernyshev
24
570
RailsConf 2023
tenderlove
29
880
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
A designer walks into a library…
pauljervisheath
202
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Navigating Team Friction
lara
183
14k
Adopting Sorbet at Scale
ufuk
73
9k
A Philosophy of Restraint
colly
203
16k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Building an army of robots
kneath
302
42k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Transcript
KotlinΛͬͯࢥͬͨ10ͷίτ ࡾࢁ խن (chocomelon) 2017/0705 fukuoka.kt #1
ࣗݾհ ࡾࢁ խن (chocomelon) ωΠςΟϒΞϓϦΛओʹ୲ 2013ϐΫγϒೖࣾ Kotlinྺ 3िؒ
ฐࣾͷKotlin࠾༻ঢ়گ
pixivʢJavaʣ
pixiv ίϛοΫʢJava & Kotlinʣ
pixiv SketchʢJavaɺKotlinʹ͍ͨ͠ʣ
PawooʢJavaɺKotlinʹ͍ͨ͠ʣ
ԬͰ৽ن։ൃதͷΞϓϦ => Kotlin
ԬͰ৽ن։ൃதͷΞϓϦ ɾKotlin ɾAndroid Architecture Components ɹɾViewModel, LiveData, Room ɾDataBinding ɾRxJava/Android
KotlinΛͬͯࢥ͏10ͷίτ
1. Extension͕͢Β͍͠ fun ImageView.setImageUrl(imageUrl: String?) { if (imageUrl == null
|| !URLUtil.isValidUrl(imageUrl)) { return } Glide.with(context).load(imageUrl).into(this) }
2. ؔܕ࠷ߴ͔Α arrayOf(1, 2, 3, 4, 5) // 1, 2,
3, 4, 5 .filter { it % 2 == 0 } // 2, 4 .map {it * 2 } // 4, 8 .sum() // 12
3. σϑΥϧτҾ/͕ศར fun hoge(fugaString: String, fooInt: Int = 0, barBoolean:
= true) { // Do something } val fuga: Int = optionalVal1 ?: 5
4. when͕εϚʔτ viewModel?.getDataSourceState()?.observe(this, Observer { when (it) { DataSourceState.SUCCESS ->
infoView.setType(InfoView.Type.HIDE) DataSourceState.LOADING -> infoView.setType(InfoView.Type.LOADING) DataSourceState.EMPTY_DATA -> infoView.setType(InfoView.Type.NOTFOUND) DataSourceState.ERROR -> infoView.setType( InfoView.Type.ERROR, View.OnClickListener { reload() }) } })
5. SmartCast͕ྑ͍ fun hoge(optionalVal1: String?, optionalVal2: String?) { if (optionalVal1
!= null && optionalVal2 != null) { val hoge = optionalVal1 + optionalVal2 // Do something } } if (object is Person) { print(object.name) }
6. είʔϓ͕ؔศར class HogeActivity: AppCompatActivity() { companion object { val
BUNDLE_KEY_HOGE_INT = "HOGE_INT" fun createIntent(context: Context, hogeInt: Int): Intent = Intent(context, HogeActivity::class.java).apply { putExtra(BUNDLE_KEY_HOGE_INT, hogeInt) } } }
7. let let ͕Ϝζ͍ optionalVal1?.let { optionalVal1 -> optionalVal2?.let {
optionalVal2 -> // Do something } }
7. let let ͕Ϝζ͍ if (optionalVal1 != null || optionalVal2
!= null) { return } // Do something
7. let let ͕Ϝζ͍ optionalVal1 ?: optionalVal2 ?: return //
Do something
7. let let ͕ຊʹϜζ͍ inline fun <S, T, R> let(s:
S?, t: T?, block: (s: S?, t: T?) -> R) { if (s != null && t != null) { block(s, t) } } let(optionalVal1, optionalVal2) { optionalVal1, optionalVal2 -> // Do something }
8. Gson͍ͬͯΔ߹ҙ✋ ɾNonNullͷobjectʹNull͕ೖͬͯ͘Δ ɾύʔε࣌Θ͔Β࣮ͣߦ࣌ʹࢮ͵ ɾmoshi͓͏ https://github.com/square/moshi
9. AndroidΤϯδχΞ͕Δؾ ɾؓࢄͱͯͨ͠Slack͕Kotlinͷॻ͖ํٞ ɹͰΓ্͕Δ ɾࢼߦࡨޡָ͕͍͠ ɾ͙͢͡ΊΒΕΔ => Ұ෦Kotlinʹม͑ͯྑ͍͠ɺ ɹ ࣗಈมͦͦ͜͜༗ೳ
10. iOSͷΤϯδχΞ͕Δؾ ɾʮKotlinͩͬͨΒྑ͍Ͱ͢Αʯ ɾʮSwiftͱࣅͯΔ͡ΌΜʯ ɾʮָͦ͠͏ʢখฒʣʯ
ԬΦϑΟεͰΤϯδχΞืूத ڵຯ͕͋Δํ·ͣϥϯνͰ͠·͠ΐ͏ʂ https://www.wantedly.com/projects/90433