我正在尝试在SwiftUI中使用CoreData记录创建有序列表。如何在这样的列表中打印连续数字?
在下面的示例中,我有一个名为SomeEntity的实体,其中有一个名为title的String属性。
import SwiftUI
struct ContentView: View {
var fetchRequest: FetchRequest<SomeEntity>
var items: FetchedResults<SomeEntity> { fetchRequest.wrappedValue }
var body: some View {
NavigationView {
List {
ForEach(items, id: \.self) {item in
NavigationLink(destination: ItemDetailsView(item: item)) {
HStack {
Text("99")
// How to print running number instead of "99" in this ordered list of CoreData records?
// I was thinking about something like this:
// Text(items.id) - but this doesn't work. Is there something similar?
.multilineTextAlignment(.center)
.frame(width: 60)
Text(item.title!)
}
}
}
}
}
}
}
Text("\(item.id)")
可以吗? - iSpain17