Search code examples
androidlistkotlinargumentskotlin-null-safety

I need to get list with an argument


private fun getRadResultList() {
    safeLet(
        arguments?.getString("referenceVisitId"), arguments?.getString("facilityId")
    ) { referenceVisitId, facilityId ->
        viewModel.getRadResultsWithId(referenceVisitId, facilityId)
    }
}

This is my previous code. The number of arguments requested by the function is now one. How do I return the facilityId in getRadResults()

private fun getRadResultList() {
    safeLet(
         arguments?.getString("facilityId")
    ) {  facilityId ->
        viewModel.getRadResults( facilityId)
    }
}

This code is the latest version. getRadResult() function wants only the facilityId.


Solution

  • I'm assuming safeLetis the function mentioned in Multiple variable let in Kotlin

    The thing is, that function is only necessary when wanting to check multiple variables. With a single variable you can use the default let. So like:

    private fun getRadResultList() {
        arguments?.getString("facilityId")?.let { facilityId ->
            viewModel.getRadResults( facilityId)
        }
    }