전체 글 (93) 썸네일형 리스트형 이차원 배열 회전 fun main(){ val n = 5 val array = Array(n){ row -> IntArray(n){ 10*row + it + 1 } } val rotationArray = Array(n){ IntArray(n){ 0 } } for(i in 0 until n){ for(j in 0 until n){ rotationArray[j][n-i-1] = array[i][j] } }} 배열12345678910111213141516171819202122232425 회전21161161221712722318138324191494252015105 Data Layer DataSource네트워크, 로컬 DB, 파일, 메모리 등에서 데이터를 제공한다.데이터와 직접적인 연관이 있는 클래스이기 때문에 해당 클래스에서는 CRUD의 기능만 담당한다. DataSource 클래스에서는 하나의 데이터 저장소만 사용해야 한다.예를 들어, 네트워크 통신 DataSource에는 네트워크 통신과 관련 된 기능만 존재해야 한다.class NewsRemoteDataSource( private val newsApi: NewsApi, private val ioDispatcher: CoroutineDispatcher) { /** * Fetches the latest news from the network and returns the result. * This executes .. runCatching 예외 처리 runCatching은 Kotlin에서 제공하는 예외처리 함수로 성공, 실패에 따른 결과를 Result 객체로 변환하여 반환한다.inline fun runCatching(block: () -> R): Resultinline fun T.runCatching(block: T.() -> R): Result Result 생성runCatching 내부적으로도 try-catch문을 사용하여 작업의 성공, 실패 여부를 통해 Result 객체의 value 를 설정한다.@InlineOnly@SinceKotlin("1.3")public inline fun runCatching(block: () -> R): Result { return try { Result.success(block()) } c.. 이전 1 ··· 7 8 9 10 11 12 13 ··· 31 다음