kkumot avatar

31DaysOfKotlin 27~31

kkumot

Published: 02 Apr 2018 › Updated: 02 Apr 201831DaysOfKotlin 27~31

31DaysOfKotlin 27~31

31DaysOfKotlin 이 끝났다.

27~31에 올라왔던 내용이다.

다음 글을 계속 스팀잇에 포스팅할지는 고민좀 해봐야겠다.

Day 27. Handler with Android KTX

// 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"
}

Leave 31DaysOfKotlin 27~31 to:

Written by

Read more #ko posts


Best Posts From kkumot

We have not curated any of kkumot's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From kkumot