In one of my generics views, I define a "Content" parameter as View to be passed, as I need to present on this generics view row content from a FetchRequest in Core Data. For a swipe actions of that ForEach, I need to get the string passed from that view:
struct MyView<Object: NSManagedObject, Content: View>: View {
var items: FetchedResults<Object>
var rowContent: (Object) -> Content
init(items: FetchedResults<Object>, rowContent: @escaping (Object) -> Content) {
self.items = items
self.rowContent = rowContent
}
@State private var editingItemName = ""
var body: some View {
ForEach(items, id: \.self) { item in
rowContent(item)
.swipeActions(edge: .leading) {
Button {
editingItemName = rowContent(item)
//Here I can't get just string value. Just something like "Text(storage: SwiftUI.Text.Storage.verbatim("text_I_need_to_get"), modifiers: [])"
Which is called from another view with:
struct ParentView: View {
@FetchRequest(sortDescriptors: []) private var items: FetchedResults<MyEntity>
var body: some View {
Form {
NavigationLink(destination: MyView(items: instruments, rowContent: { item in
Text(item.name ?? "")
})) {
Label("Items", systemImage: "star")
}
//More code here
rowContent(item) in the ForEach works perfectly, but how could I grab just the string "text_I_need_to_get"?