Skip to content

Instantly share code, notes, and snippets.

@quindariuss
Last active March 22, 2020 00:40
Show Gist options
  • Save quindariuss/ab047d1410fa9e35f2221a101da3b374 to your computer and use it in GitHub Desktop.
Save quindariuss/ab047d1410fa9e35f2221a101da3b374 to your computer and use it in GitHub Desktop.
import CodeScanner
import SwiftUI
struct CodeScanner: View {
@State private var isShowingScanner = false
var body: some View {
Button(action: {
self.isShowingScanner = true
}) {
Text("Show Scanner")
}
.sheet(isPresented: $isShowingScanner) {
CodeScannerView(codeTypes: [.qr], simulatedData: "Some simulated data", completion: self.handleScan)
}
}
func handleScan(result: Result<String, CodeScannerView.ScanError>) {
self.isShowingScanner = false
switch result {
case .success(let data):
print("Success with \(data)")
case .failure(let error):
print("Scanning failed \(error)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment