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
5年分のツケを一気に払った話
soogie
3
1.3k
ROS 2のZenoh対応とZenohのROS 2対応
takasehideki
2
300
VS Code extension: ドラッグ&ドロップでファイルを並び替える
ttrace
0
170
UnJSで簡単に始めるCLIツール開発 / cli-tool-development-with-unjs
aoseyuu
2
280
2024-10-02 dev2next - Application Observability like you've never heard before
jonatan_ivanov
0
180
Progressive Web Apps for Rails developers
siaw23
2
550
CSC509 Lecture 02
javiergs
PRO
0
160
クラウドサービスの 利用コストを削減する技術 - 円安の真南風を感じて -
pyama86
3
390
データサイエンスのフルサイクル開発を実現する機械学習パイプライン
xcnkx
2
500
sqlcを利用してsqlに型付けを
kamiyam
0
240
ML-прайсинг_на_Lamoda__вошли_и_вышли__приключение_на_20_минут__Слава_Цыганков.pdf
lamodatech
0
130
色んなオートローダーを覗き見る #phpcon_okinawa
o0h
PRO
5
390
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
Design by the Numbers
sachag
278
19k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2k
The Brand Is Dead. Long Live the Brand.
mthomps
53
38k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
3
230
RailsConf 2023
tenderlove
28
840
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9k
Making the Leap to Tech Lead
cromwellryan
131
8.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
No one is an island. Learnings from fostering a developers community.
thoeni
19
2.9k
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