kmm-integration-sample
kmm-integration-sample copied to clipboard
Get value from Result.Error in swift
ContentView.swift:
func login(username: String, password: String) { if let result = loginRepository.login(username: username, password: password) as? ResultSuccess { print("Successful login. Welcome, (result.data.displayName)") } else { print("Error while logging in") } }
login DataSource:
class LoginDataSource { fun login(username: String, password: String): Result<LoggedInUser> { try { // TODO: handle loggedInUser authentication val fakeUser = LoggedInUser(randomUUID(), "Jane Doe") return Result.Success(fakeUser) } catch (e: Throwable) { return Result.Error(RuntimeException("Error logging in", e)) } } fun logout() { // TODO: revoke authentication }}
how to get RuntimeException message if Result not success from ContentView.swift?