I'm trying to debug why some code isn't being executed on iOS and I'm wondering if anybody can give me some debugging tips. I'm not seeing any errors. It is basically calling into code structured like "refreshBreeds()" in KaMPKit. I see that it goes into the method in the BreedViewModel equivalent for refreshBreeds. I can step over the call to viewModelScope.launch, but the code in the launch block isn't ever executed.
r
russhwolf
06/03/2022, 10:10 PM
Which IDE are you debugging in? And what does the line where you're setting the breakpoint look like? I've found debugging from xcode can sometimes do a better job of handling inline lambdas.
t
Trey
06/03/2022, 10:41 PM
I’m using xcode with the touch labs plugin. What would I look for? The lambda isn't executed.
r
russhwolf
06/03/2022, 10:52 PM
Oh i see, I think I misread your original message. I thought you weren’t hitting a breakpoint in the debugger, not that the code wasn’t being executed.
Maybe try swapping dispatchers and see if anything changes. I’ve seen it happen sometimes that you call something from the main thread and dispatch something else to the main thread, but because the thread is occupied the launch never triggers.
t
Trey
06/06/2022, 8:58 PM
Anything else you can think of for me to try? I wrapped the call to viewModelScope.launch in a defaultScope.launch and the lambda for it isn't being called either (private val defaultScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)). I'm not sure how to print out the state of the current thread, since this is in commonMain running on iOS.
Trey
06/06/2022, 8:59 PM
Also, I've compared my project settings to KaMPKit. I even updated KaMPKit to use the same versions in the toml file that my project is using. KaMPKit calls the lambda fine, but not my project. I know it must be something simple I've missed.
Trey
06/06/2022, 9:51 PM
I figured it out. My view model was getting cleared before I called launch, which would cancel the scope.