Skip to content

Instantly share code, notes, and snippets.

View haroldjose30's full-sized avatar
🎯
Focusing

Harold José haroldjose30

🎯
Focusing
View GitHub Profile
@haroldjose30
haroldjose30 / Swift_as_Kotlin.swift
Last active December 7, 2024 00:08
Swift as Kotlin
// Returns the value if the predicate evaluates to `true`; otherwise, returns `nil`.
// this function is similar from kotlin takeIf
//
// let number: Int? = 42
// let result = number.takeIf { $0 > 40 } // Output: Optional(42)
// let invalidResult = number.takeIf { $0 < 40 } // Output: nil
//
// let string: String? = "some text"
// let resultString = string.takeIf { !$0.isEmpty } // Output: Optional("some text")
// let invalidResultString = resultString.takeIf { $0.isEmpty } // Output: nil
@haroldjose30
haroldjose30 / LoginUseCase.kt
Last active June 3, 2022 12:40
LoginUseCase from Shared KMM to be used in IOS Swift
sealed class Resource<T> (
val data: T? = null,
val message: String? = null
) {
class Success<T>(data: T) : Resource<T>(data)
class Loading<T>(data: T? = null) : Resource<T>(data)
class Error<T>(message: String, data: T? = null) : Resource<T>(data, message)
}
class LoginUseCase constructor(private val iUserRepository: IUserRepository) {
@haroldjose30
haroldjose30 / Collector.swift
Created June 3, 2022 12:26
KMM Wrapper Kotlin Flow with Swift
//References:
//https://johnoreilly.dev/posts/kotlinmultiplatform-swift-combine_publisher-flow/
//https://github.com/Kotlin/kotlinx.coroutines/issues/2306
//https://stackoverflow.com/questions/64175099/listen-to-kotlin-coroutine-flow-from-ios
//https://mmmnnnmmm.com/kotlin-kmm-swift-ios-stateflow.html
import Foundation
import shared
class Collector<T>: Kotlinx_coroutines_coreFlowCollector {