jean
07/10/2023, 8:21 PMimport KMPNativeCoroutinesAsync
I get Could not find module 'KMPNativeCoroutinesAsync' for target 'x86_64-apple-ios-simulator'
and if I don’t add it I get Cannot find 'asyncResult' in scope
(Yes I added the dependency from Xcode File > Add Packages. I use “branch” and “master” because it can’t resolve the dependency with version options)Rick Clephas
07/10/2023, 8:25 PMKMPNativeCoroutinesAsync
is indeed the one for the asyncResult(for:)
function.Rick Clephas
07/10/2023, 8:25 PMKMPNativeCoroutinesAsync
also part of your targets framework dependencies?Rick Clephas
07/10/2023, 8:26 PMRick Clephas
07/10/2023, 8:28 PM1.0.0-ALPHA-13
should be accepted by Xcode.Ahmed Elshaer
07/10/2023, 10:05 PMAhmed Elshaer
07/10/2023, 10:06 PMSanjayKarki
07/11/2023, 3:44 AMRick Clephas
07/11/2023, 4:41 AMRick Clephas
07/11/2023, 4:42 AMSanjayKarki
07/11/2023, 5:28 AMpackage com.outcodesoftware.outcodesuite.framework
import com.rickclephas.kmm.viewmodel.KMMViewModel
import com.rickclephas.kmm.viewmodel.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
abstract class BaseVM<Event, VState>(val overrideSuccess: Boolean = false): KMMViewModel() {
abstract fun initState(): VState
abstract fun onHandleEvent(event: Event)
abstract fun logState(state: VState)
abstract fun <T> responseToState(it: AppResult<T>)
protected val state: VState by lazy {
initState()
}
// private var uiState = MutableStateFlow(viewModelScope = viewModelScope,value = state)
// var uiStateUI = uiState.asStateFlow()
//
// fun setState(newState: VState){
// viewModelScope.coroutineScope.launch {
// delay(200)
// uiState.value = newState
// logState(state)
// }
// }
}
Rick Clephas
07/11/2023, 5:32 AMSanjayKarki
07/11/2023, 5:36 AMRick Clephas
07/11/2023, 6:20 AMjean
07/11/2023, 7:23 AMCould not find module 'KMPNativeCoroutinesAsync' for target 'x86_64-apple-ios-simulator'; found: arm64-apple-ios-simulator, at: /Users/.../Debug-iphonesimulator/KMPNativeCoroutinesAsync.swiftmodule
Rick Clephas
07/11/2023, 7:38 AMKMPNativeCoroutinesAsync
is listed under “Frameworks, Libraries, and Embedded Content” in you targets general settings?jean
07/11/2023, 7:45 AMjean
07/11/2023, 8:03 AMimport KMPNativeCoroutinesAsync
🤔Rick Clephas
07/11/2023, 8:55 AMRick Clephas
07/12/2023, 4:44 PMjean
07/12/2023, 6:26 PMjean
07/12/2023, 7:53 PM// Generated code inside the shared library
public val HomeScreenHelper.stateFlow: NativeFlow<HomeScreenState>
get() = state.asNativeFlow(null)
// Inside the ios app
@State private var viewState: HomeScreenState
...
private func observeStateChanges() {
createPublisher(for: homeScreenHelper.stateFlow).sink { completion in
print("Received completion: \(completion)")
} receiveValue: { value in
viewState = value
}
}
It compiles but nothing happens. In the Readme page it says let publisher = createPublisher(for: clock.time)
but I guess it should be clock.timeFlow
?Rick Clephas
07/12/2023, 7:58 PMtime
or timeFlow
(or in your case state
or stateFlow
). The @NativeCoroutines
annotation reuses the original property name for the Flow
property, which would result in time
. However if you use @NativeCoroutinesState
then the name is reused for the value property, exposing the flow itself as timeFlow
.
So depending on your use case you can pick the annotation that will result in the most logical Swift property name.Rick Clephas
07/12/2023, 8:00 PMobserveStateChanges
since the AnyCancellable
returned by sink
gets deallocated. Storing the cancellable in a property will prevent that.jean
07/12/2023, 9:43 PMlet cancellable = createPublisher...
🤔Rick Clephas
07/13/2023, 5:15 AMimport Combine
class MyClass {
var cancellable: AnyCancellable? = nil
func observeStateChanges() {
cancellable = createPublisher(for: ...).sink { ... }
}
}
jean
07/13/2023, 7:29 AMNick
08/10/2023, 8:49 PMKMPNativeCoroutinesAsync
either as they weren't found.I discovered that for some reason it was importing some really old version of KMPNativeCoroutines
that probably didn't have KMPNativeCoroutinesAsync
.
Solution: remove the swift package (when you go to add a package, right click on the package in the "recently used" column, and click on remove.
Add it back but this time select the master branch instead of specifying the version.
It's probably not ideal but this is the only way I could get it to work.
I know nothing about xcode and how it works so I probably did something wrong along the way.Rick Clephas
08/10/2023, 8:54 PM1.0.0-ALPHA-14
) should work. Please let me know if that isn't the case.Nick
09/11/2023, 6:52 PM