31DaysOfKotlin 이 끝났다.
27~31에 올라왔던 내용이다.
다음 글을 계속 스팀잇에 포스팅할지는 고민좀 해봐야겠다.
Day 27. Handler with Android KTX
- https://kotlinlang.org/docs/reference/lambdas.html
- https://github.com/android/android-ktx/blob/master/src/main/java/androidx/core/os/Handler.kt#L38
// Android KTX API
fun Handler.postDelayed(delay: Int /* ... */, action: () -> Unit)
// Call it like this - no need for a Runnable in your code
handler.postDelayed(50) {
// pass a lambda to postDelayed
}
Day 28. Spannable String Builder
val string = buildSpannedString {
append("no styling text")
bold {
append("bold")
italic {
append("bold and italic")
}
}
inSpans(RelativeSizeSpan(2f), QuoteSpan()){
append("double sized quote text")
}
}
Day 29. Parcelize with Kotlin
@Parcelize
data class User(val name: String, val occupation: Work): Parcelable
// build.gradle
androidExtensions {
// Enable experimental kotlin features in gradle to enable Parcelize
experimental = true
}
Day 30. View extension with Android KTX
view.updatePadding(left = newPadding)
view.updatePadding(top = newPadding)
view.updatePadding(right = newPadding)
view.updatePadding(bottom = newPadding)
view.updatePadding(top = newPadding, bottom = newPadding)
Day 31. let, apply, with, run
val string = "a"
val runResult = string.run {
// this = "a"
// it = not available
1 // Block return value
// result = 1
}
val letResult = string.let {
// this = this@MyClass
// it = "a"
2 // Block return value
// result = 2
}
val withResult = with(string) {
// this = "a"
// it = not available
3 // Block return value
// result = 3
}
val applyResult = string.apply {
// this = "a"
// it = not available
4 // block return value unused
// result = "a"
}
Congratulations @kkumot! You received a personal award!
Click here to view your Board
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @kkumot! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit