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

Question: Creating an instance of Result<V, E> in Swift #108

Closed
curioustechizen opened this issue Aug 7, 2024 · 3 comments
Closed

Question: Creating an instance of Result<V, E> in Swift #108

curioustechizen opened this issue Aug 7, 2024 · 3 comments

Comments

@curioustechizen
Copy link

I've been using Result<V, E> for quite some time in a KMP project targeting Android and iOS. I've successfully consumed instances of Result from Swift. It is not pretty and results in some loss of safety but it works.

Now I have a situation where I want to produce an instance of Result from Swift. Are there examples on how to go about doing this?

@michaelbull
Copy link
Owner

Creating a Result is achieved by calling the Ok/Err functions.

Some initial Googling of calling Kotlin code in Swift returns this article and this example repo which has interoperability examples.

Hope that helps.

@curioustechizen
Copy link
Author

Sorry somehow this notification slipped through my fingers.

I'm aware of the basics of calling Kotlin code from Swift. The problem was more related to how to make the Ok() and Err() constructors visible from the Swift side, especially if kotlin-result is a transitive dependency and not visible to the Swift side directly.

For now I refactored my code to avoid having to create instances of kotlin-result on the Swift side. However if I end up having more situations that require this then I will revisit and post a follow up here.

@sayah-y
Copy link

sayah-y commented Aug 18, 2024

@curioustechizen please take a look to the following issue:
#109

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

3 participants