Debugging iPad app that only fails on real device?

33 Views Asked by At

I have a SwiftUI app working perfectly in XCode and iPadOS 17 simulator. When I run it on a real iPad it works well until I tap a specific List line which is meant to open an editing panel. The app then freezes. It does not post any warnings or crash. If I pause it, it opens into ?assembly code rather than a line in my own code, and if I run one line, it shows me whatever code page I was looking at. I am after advice about how to debug this please? Any thoughts please as to how to proceed?

I have looked at multiple Apple, Stack Overflow and other SwiftUI resources and cannot find a similar problem. I don't even know where to put print statements to see what the loop might be. I have obviously made some mistake but have no idea how to track it down. This app has taken over a year to create and this is the first time this has appeared.

1

There are 1 best solutions below

0
On

For someone else who experiences this. It is somewhat obtuse though and I suspect an Apple oversight. I looked at similar code that was working. The commonality was clicking on a List item, causing a NavigationLink(destination:) to trigger. The destination in the working version was a specific View instantiation. The call in the failing destination was a function which called a base object function "destinationView(object:)". This returned an AnyView since different subclass objects which override this function returned different views (and I have not been able to determine how to override functions which return "some View"). The AnyView was confusing SwiftUI's NavigationLink somehow leading to an infinite loop. By replacing the destination function to specifically return specific Views (as appropriate for each type of object using multiple if statements with "as? ObjectType"), the issue resolved. Moral: use of AnyView should be avoided wherever possible (as Apple recommends!). Hope that helps someone else.