Help!! I only Get this error “type () cannot conform to view”

import SwiftUI

import CodeScanner



struct ScannerView: View {

    @State var isPresentingScanner = false

    @State var ScannedCode: String = "Produkt"

    

    

    var scannerSheet : some View {

        CodeScannerView(

            codeTypes: [.ean13],

            completion: { result in 

                if case let .success(code) = result {

                    self.ScannedCode = code.string

                    self.isPresentingScanner = false

                }

            }

        )

    }

    var body: some View {

        

        NavigationView {

        VStack {

            

            Button("Scan Strekkode") {

                self.isPresentingScanner = true

            }

            .frame(width: 200, height: 50,

                   alignment: .center)

            .background(Color.black)

            .foregroundColor(Color.orange)

            .cornerRadius(8)

            

            .sheet(isPresented: $isPresentingScanner) {

                self.scannerSheet

            }

            

            List {

                var Produkt = [""]

                Produkt.append(ScannedCode)

                Section(header: Text("Produkt")) {

                    Text(Produkt[1])

                    Text(Produkt[2])

                }

            }

        }

            

        }

        .navigationTitle("Scanner")

        .navigationBarTitleDisplayMode(.inline)

        

    }

    

}

In SwiftUI, you can't just put arbitrary code in a viewBuilder which is expecting a view.

Try:

            List {
//                var Produkt = [""]
//                Produkt.append(ScannedCode)
                Section(header: Text("Produkt")) {
                    Text(Produkt[1])
                    Text(Produkt[2])
                }

...you will have to append your ScannedCode somewhere else!

Help!! I only Get this error “type () cannot conform to view”
 
 
Q