Post marked as solved
Post marked as solved with 2 replies, 1,430 views
I am trying to create a Multiplatform Document Based app using SwiftUI.
I have a List which the user can reorder by dragging Items using .onMove. It works fine in macOS but crashes iOS every time with the above message alongside @main
The relevant code is-
struct ContentView: View {
…
List {
ForEach(Array(document.journey.items.enumerated()), id: \.1.id) { (index, item) in
Section {
HStack {
Text("\(index+1)")
…
Text("\(item.address)"
…
} // End HStack
.background(
Capsule()
.fill((selection.contains(item.id) ? Color.red : Color.blue))
.onTapGesture(perform: {
if selection.contains(item.id) {
selection.remove(item.id)
} else {
selection.insert(item.id)
}
})
)
.font(.headline)
.foregroundColor(.white)
} // End Section
…
} // End ForEach
.onDelete(perform: delete)
.onMove { offsets, toOffset in
document.moveItems(offsets: offsets, toOffset: toOffset, undoManager: undoManager)
}
} // End List
////////
final class MultiStopDocument: ReferenceFileDocument {
…
func moveItems(offsets: IndexSet, toOffset: Int, undoManager: UndoManager? = nil) {
let oldItems = journey.items
// BREAK POINT
print("GOT to First")
withAnimation {
journey.items.move(fromOffsets: offsets, toOffset: toOffset)
}
print("GOT to Second")
#if os(macOS)
undoManager?.registerUndo(withTarget: self) { doc in
doc.replaceItems(with: oldItems, undoManager: undoManager)
}
#endif
}
///////////
import SwiftUI
@main - Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1af84999c)
struct MultiStopApp: App {
Console macOS stepping :-
GOT to First
GOT to Second
Console iOS stepping :-
2023-06-07 12:03:16.869439+0100 MultiStop[27341:6172177] -[UITextEffectsWindow _accessibilityFindSubviewDescendant:]: unrecognized selector sent to instance 0x112037400
GOT to First
2023-06-07 12:03:52.083774+0100 MultiStop[27341:6172433] XPC connection interrupted
GOT to Second
THEN CRASH