Post not yet marked as solved
Post marked as unsolved with 1 replies, 230 views
I'm new to this coding thing and I came across this error saying "Cannot assign value of type 'ScanResult' to type 'String'" in the line "self.scannedCode = code"
The attached is my code for reference
import SwiftUI
import CodeScanner
struct print: View {
@State var isPresentingScanner = false
@State var scannedCode: String = "Scan QR code on mask box"
var scannerSheet : some View {
CodeScannerView(
codeTypes: [.qr],
completion: { result in
if case let .success(code) = result {
self.scannedCode = code
self.isPresentingScanner = false
}
}
)
}
var body: some View {
VStack(spacing: 10) {
Text(scannedCode)
Button ("Scan QR Code") {
self.isPresentingScanner = true
}
.sheet(isPresented: $isPresentingScanner) {
self.scannerSheet
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
print()
}
}