31DaysOfKotlin 27~31

in ko •  7 years ago 

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"
}
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @kkumot! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @kkumot! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

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!