Quantcast
Viewing all articles
Browse latest Browse all 86

How to apply strikethrough() to a tapped foreach Text item in SwiftUI?

I'm trying to apply a strikethrough to any tapped Text items in a ForEach loop:

struct BrandListView: View {    @ObservedObject var list: ListObject    var body: some View {        ScrollView {            VStack {                ForEach(list.items) { items in                        Text(item.name)                            .strikethrough(//?)                            .onTapGesture(perform: {                                // on tap, apply strikethrough only to this item.                            })                }            }        }    }}

Is there an easy way to apply a condition using @State var, to track when to apply strikethrough() or not? I'm thinking the only way is to put a property into the listObject that tracks whether it is striked or not, and then use that to apply true/false to the strikethrough() modifier. But that seems like spaghetti code?


Viewing all articles
Browse latest Browse all 86

Trending Articles