본문 바로가기

android/Kotlin6

Kotlin DI 라이브러리 Koin DI는 구성요소간의 의존 관계가 소스코드 내부가 아닌 외부 설정 파일등을 통해 정의되게하는 디자인 패턴중 하나입니다. project 수준의 gradle에 아래 내용을 추가합니다 . koin_version = '2.0.0-rc-2' repositories { jcenter() } 그리고 앱수준의 gradle에 아래와 같은 dependency를 추가합니다 implementation "org.koin:koin-android:$koin_version" /** 아래는 옵션으로 필요한 부분이 있으면 추가해줍니다 **/ - Core features // Koin for Kotlin implementation "org.koin:koin-core:$koin_version" // Koin extended & experim.. 2020. 5. 26.
Kotlin Collections Mutable VS Immutable Mutable val mutableList: MutableList = mutableListOf(1,2,3,4,5) mutableList.add(6) for(i in 0 until mutableList.size){ println(mutableList.get(i)) //1, 2, 3, 4, 5, 6 } Immutable val immutableList: List = listOf(1,2,3,4,5) immutableList.add(6) // Error immutableList.plus(6) // Ok for(i in 0 until immutableList.size){ println(immutableList.get(i)) //1, 2, 3, 4, 5 } Kotlin은 함수형.. 2020. 4. 19.
Kotlin StandardLib let with apply run also takelf, takenless use prepeat Standard data class Person(var name: String = "junhyeok", var age: Int = 18) val person = Person() let data class Person(var name: String = "junhyeok", var age: Int = 18) val person = Person() inline fun T.let(block: (T) -> R) : R = block(this) -------------------------------------- val name = person.let { it.name } println(name) // junhyeok .. 2020. 4. 17.
Kotlin Expression KotlinExpression Expression(if-else) /* java */ int a = 5; int b = 10; int maxValue = a; if (a > b) { maxValue = a; } else { maxValue = b; } /* kotlin */ val a = 5 val b = 10 // Traditional usage var maxValue = a if (a b) { max = a } else { max = b } val max = if (a > b) { print("Choose a") a } else { print("Choose b") b } java와 다르게 kotlin 에서는 .. 2020. 4. 16.