- Supported Symbologies
- Creating the Project
- Coding the App
- Testing the App
- Appendix: Code for ScannerViewController.swift
Creating the Project
Using Xcode, create a new project and name it BarcodeScanning. Next, add the AVFoundation.framework to the project (see Figure 1).
Figure 1 Adding the AVFoundation.framework to the project.
Add a barcode.png image and a WAV file named beep.wav to the project, as shown in Figure 2.
Figure 2 Adding an image to the project.
Select the Main.storyboard file in the project. In the View window, add a Button and set its image to barcode.png. Next, add a Label view below the button (see Figure 3).
Figure 3 Populating the View window with a button and a label.
Add a new View Controller to the storyboard, Control-click the button in the first View Controller, and drag it over the newly added View Controller. When the pop-up appears, select Present Modally. The storyboard should now look like Figure 4.
Figure 4 The segue connecting the two View Controllers.
Add a new Cocoa Touch Class file to the project. Name it ScannerViewController and make it a subclass of UIViewController. You should now have a new file named ScannerViewController.swift (see Figure 5).
Figure 5 The new class added to the project.
Back in the Storyboard Editor, set the Class of the second View Controller to ScannerViewController (see Figure 6).
Figure 6 Setting the second View Controller's class to ScannerViewController.