brabo-hi
07/25/2023, 3:31 PMResult<String>
how can i parse it in Swift IOS ? I it is giving me Any?
valueJeff Lockhart
07/25/2023, 3:40 PMAny?
value to String
. You could create a Swift extension that does this cast to make the API nicer within Swift.brabo-hi
07/25/2023, 3:44 PMsuspend fun process() : Result<MyCustom>{}
what will be the best way to parse it in Swiftkevin.cianfarini
07/25/2023, 3:49 PMkevin.cianfarini
07/25/2023, 3:49 PMAny?
when using value classes in swift.Jeff Lockhart
07/25/2023, 3:54 PMkevin.cianfarini
07/25/2023, 3:57 PMvalue class Foo(val string: Stirng)
says it should be exposed as String in Swift, but I’ve never seen that. It always gets case to Any?
for me.Jeff Lockhart
07/25/2023, 3:58 PMkevin.cianfarini
07/25/2023, 3:59 PMJeff Lockhart
07/25/2023, 5:39 PMJeff Lockhart
07/25/2023, 5:42 PMResult
type that is a regular class, instead of value class.brabo-hi
07/25/2023, 11:00 PMResult
like type with a success
class or failure
class depending on the operationkevin.cianfarini
07/26/2023, 1:02 AMsealed interface MyResult<out T> {
class Success(val data: T) : MyResult<T>
class Failure(val e: Throwable) : MyResult<Nothing>
}
Jeff Lockhart
07/26/2023, 4:21 AMbrabo-hi
07/26/2023, 4:29 AMLoe
10/17/2023, 1:52 AM/**
* Adapted from [Result](<https://github.com/google/iosched/blob/main/shared/src/main/java/com/google/samples/apps/iosched/shared/result/Result.kt>)
* this class is used because [Kotlin.Result] can't be accessed from iOS.
* This class won't be needed once the [Result.kt issue](<https://youtrack.jetbrains.com/issue/KT-32352/inline-classes-are-exported-as-id-to-objc-swift#focus=Comments-27-6766899.0-0>) is addressed
*/
sealed class Result<out R> {
data class Success<T>(val data: T) : Result<T>()
data class Failure(val exception: Exception) : Result<Nothing>()
}
/**
* `true` if [Result] is of type [Success] & holds non-null [Success.data].
*/
val Result<*>.isSuccess
get() = this is Result.Success && data != null
val <T> Result<T>.data: T? get() = (this as? Result.Success)?.data
val <T> Result<T>.failureData: Exception? get() = (this as? Result.Failure)?.exception
brabo-hi
10/17/2023, 5:29 AM