I run into interesting problem on iOS. I have a Sw...
# multiplatform
p
I run into interesting problem on iOS. I have a SwiftUI view:
struct MyView: View {
@State var path = NavigationPath()
body with NavigationStack....
func openDetail() {
path.append("mystring")
print("path: \(path.count)")
}
}
When I call openDetail() from my KMM code, the State var path seems not to be updated. Prints "path: 0" (and therefore the navigation doesn't work). The whole MyView is not getting reinitialized (init is not called) Any ideas?
p
It works if you call this code from ios? It’s hard to say what might be wrong with the stack not visible in the snippet
p
Yep, it seems to work. I have a trivial NavigationStack whis is bound to the navigationPath, but I feel the core problem is in the fact @State is not updated - I append the element, and when I read from it on the next line, it is not there.
p
How do you call this method in KMM?
KMM integrates using Objective-C so I think passing a struct to any KMM code will result in a copy being made
but it depends how you integrate with KMM
p
Thanks for tips, in the meantime I think I discovered the root cause, which lies in SwiftUI and has nothing to do with KMM. Still don't understand the details fully, but changing the @State to @ObservedObject did the trick for me.
p
👍