Reputation: 1659
I am building a barcode scanner on iOS using swift. This worked perfectly when I first wrote the code but I recently returned to the programming and dicovered that it's throwing some errors. I have an exit scan button when the user press the button, it should exit the scanning mode
this is the exitScan button
let exitScanButton: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = UIColor(r: 80, g: 101, b: 161)
button.setTitle("Exit", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget( nil, action: #selector(exitScan), for:.touchUpInside)
return button
}()
this is my exitScan function
func exitScan() -> Void {
//Go back to ViewController
[self.captureSession, stopRunning];
[self.videoPreviewLayer, removeFromSuperlayer];
self.videoPreviewLayer = nil;
self.captureSession = nil;
self.navigationController?.popToRootViewController(animated: true)
}
Xcode is throwing two errors
Use of unresolved identifier 'stopRunning'
Use of unresolved identifier 'removeFromSuperlayer'
How is this an error and how can I fix this?
Upvotes: 0
Views: 90
Reputation: 6170
It's objective-c syntax.
In Swift:
self.catpureSession.stopRunning()
self.videoPreviewLayer.removeFromSuperLayer()
no semicolons also.
Upvotes: 1