Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get value from Result.Error in swift #2

Open
ysavr opened this issue Jun 10, 2021 · 0 comments
Open

Get value from Result.Error in swift #2

ysavr opened this issue Jun 10, 2021 · 0 comments

Comments

@ysavr
Copy link

ysavr commented Jun 10, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant