Source code: ```fun getCityById(selectedCityId: In...
# android
o
Source code:
Copy code
fun getCityById(selectedCityId: Int): City {
    var city : City? = null
    viewModelScope.launch {
        city = locationRepository.getSingleCityFromDatabaseById(selectedCityId)
    }
    return city //Compilation error message: type mismatch, Required:City, found: City?
}

fun getListOfLanguagesByIds(selectedLanguages: List<Int>): List<Language> {
    viewModelScope.launch {
        return supportedLanguagesRepository.getLanguagesFromDatabaseById(selectedLanguages.toIntArray())
    }// Compilation error above message: 'return' is not allowed here
}

fun getExpertiseFieldById(expertiseFieldId: Int): ExpertiseField {
    lateinit var expertiseField : ExpertiseField
    viewModelScope.launch {
        expertiseField = expertiseFieldsRepository.getSingleExpertiseFieldFromDatabaseById(expertiseFieldId)
    }
    return expertiseField
    //Seems to work, but I am afraid expertiseField will be returned uninitialized.
}
r
why you do not use LiveData?