I am attempting to call a move() method to move the order of a NavigationList in a NavigationView. I can’t figure out how to make each Links line identifiable. I have seen ForEach used that builds a List and gives each an id: but my code is a bit different. Any guidance in the right direction to help my studies would be great. Much appreciated.
I keep getting errors:
Next to the .onMove:
Value of type ‘NavigationLink<HStack<TupleView<(some View, Text)>>, DetailView>’ has no member ‘onMove’
Next to the function:
Cannot call value of non-function type ‘Binding’
Value of type ‘ObservedObject.Wrapper’ has no dynamic member ‘move’ using key path from root type ‘TitleModel’
…with the following code:
import SwiftUI
struct MyFlightView: View {
//reference the view model
@ObservedObject var model = TitleModel()
var body: some View {
NavigationView {
List(model.titles) { title in
NavigationLink(destination: DetailView(detail: title),
label: {
HStack(spacing: 20.0) {
Image(title.image1)
.resizable()
.scaledToFill()
.frame (width: 50, height: 50, alignment: .center)
.clipped()
.cornerRadius(5)
Text(title.title)
}
})
.onMove(perform: move)
}
.toolbar {
EditButton()
}
.navigationBarTitle("MyFlight")
}
}
func move(from source:IndexSet, to destination: Int) {
$model.move(fromOffsets: source, toOffsets: destination)
}
}
struct MyFlightView_Previews: PreviewProvider {
static var previews: some View {
MyFlightView()
}
}