Erase random words in sentences each time I click on a button

Hi ! I need help for coding something :

I want a function to erase random words on it, I tried everything found in the internet, nothing's worked. (here's my code : ) Anyone could give an eye to it? Many thanks

struct ContentView: View { @State private var showScannerSheet = false @State private var texts:[ScanData] = [] var body: some View {

    NavigationView {
        ZStack {
            Color.white
                .ignoresSafeArea()
        VStack{
            if texts.count > 0{
                List{
                    ForEach(texts){text in
                        NavigationLink(
                            destination:ScrollView{Text(text.content)
                                .padding()},
                            label: {
                                Text(text.content).lineLimit(1)
                               
                                
                            })
                        
                    }
                }
            }
            else{
                Button(action: {
                    self.showScannerSheet = true
                }, label : {
                    VStack {
                        Image(systemName: "doc.text.viewfinder")
                            .resizable()
                            .frame(width: 200, height: 200)
                            .font(.title)
                          
                        
                        
                        VStack {
                            
                            Text("Scan here to begin !")
                            
                        }.padding()
                        
                        
                        
                    }
                })
                .sheet(isPresented: $showScannerSheet, content: {
                    makeScannerView()
                    
                })
            }
            }
        }
         
    }
}
private func makeScannerView()-> ScannerView {
    ScannerView(completion: {
        textPerPage in
        if let outputText = textPerPage?.joined(separator: "\n").trimmingCharacters(in:
                .whitespacesAndNewlines){
            let newScanData = ScanData(content: outputText)
            self.texts.append(newScanData)
            
            let numberOfWordsToRemove = 5
            let modifiedText = removeRandomWordsInScanData(newScanData, numberOfWordsToRemove : numberOfWordsToRemove)
            
            newScanData.content = modifiedText
            return ScannerView(completion: {
                
            })
        }
        self.showScannerSheet = false
    })
}

} #Preview { ContentView() }

Replies

You did not provide code that we can try.

Where is ScannerView defined ?

How is ScanData defined ?

Where does removeRandomWordsInScanData come from ?

Hi, yes both ScannerView y ScanData are defined. The other one is something i tried but deleted now cause it didn’t work