kmm-integration-sample icon indicating copy to clipboard operation
kmm-integration-sample copied to clipboard

Get value from Result.Error in swift

Open ysavr opened this issue 3 years ago • 0 comments

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?

ysavr avatar Jun 10 '21 03:06 ysavr