I have a project with various class files. I have a barcode scanner which I have used from an online source which outputs the values in an alert controller. What I would like to do is take the barcode value and pass it back to a my main class and using a function parse it and display it in the relevant labels. For some reason I cannot get it to do this if anybody has any ideas that would be great. I have spent all day trying to figure this out without any luck.
barcodeScanner class relevant section
/* AVCaptureMetadataOutputObjectsDelegate */
func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
if alertController != nil {
return
}
if metadataObjects != nil && metadataObjects.count > 0 {
if let machineReadableCode = metadataObjects[0] as? AVMetadataMachineReadableCodeObject {
// get the barcode string
let type = machineReadableCode.type
let barcode = machineReadableCode.stringValue
I need to get the barcode let value above to the passengerInformation class where it will be passed through submitCodeAuto function to write the labels.
passengerInformation().self.submitCodeAuto(barcode)
My crack at it above which doesn't seem to work..
// display the barcode in an alert
let title = "Barcode"
let message = "Type: \(type)\nBarcode: \(barcode)"
displayAlert(title, message: message)
}
}
}
}
passengerInformation class
@IBOutlet weak var firstNameResponse: UILabel!
@IBOutlet weak var lastNameResponse: UILabel!
@IBAction func submitCodeAuto(sender: AnyObject!) {
firstNameResponse.text = barcodeProtocol(barcode).firstName
lastNameResponse.text = barcodeProtocol(barcode).lastName
}
Above the submitCodeAuto function also sends the incoming barcode through another function called barcodeProtocol which formats it allowing for first and last name to be retrieved.
I have currently tested the labels with a button running a textfield value through barcodeProtocol and displaying in the labels so that all is working.
I have also hooked up a button to a new viewcontroller with the scanner class that works fine. Showing the camera scanning and displaying the value.
but I just haven't been able to join them up. The app is returning fatal error: unexpectedly found nil while unwrapping an Optional value
Any help would be great thanks.