Get Started With The Parser#

The parser parses data strings, e.g. as found in barcodes, into a set of key-value mappings. These data formats are supported: Health Industry Bar Code (HIBC), GS1 Application Identifier (parser/AI) system, AAMVA Driver License/Identification, ICAO Machine Readable Travel Document (parser/MRTD) and Swiss QR Codes, VIN Vehicle Identification Number.

More data formats will be added in future releases. Please contact us if the data format you are using is not yet supported, or you want to use the parser on a currently unsupported platform.

Prerequisites#

Before starting with adding a capture mode, make sure that you have a valid Scandit Data Capture SDK license key and that you added the necessary dependencies. If you have not done that yet, check out this guide.

Note

You can retrieve your Scandit Data Capture SDK license key, by signing in to your account at ssl.scandit.com.

Create the Data Capture Context#

The first step to add barcode capture capabilities to your application is to create a new data capture context. The context expects a valid Scandit Data Capture SDK license key during construction.

self.context = DataCaptureContext(licenseKey: "-- ENTER YOUR SCANDIT LICENSE KEY HERE --")

Use the Parser#

In a nutshell, the parser provides functionality to transform a data string and into a list of key-value pairs. To use this functionality in your app, first the parser must be instantiated with the desired format. The result is then returned in a result object. The following sample shows how the parser code typically looks like.

#import <ScanditParser/ScanditParser.h>
...
do {
  let parser = try Parser(context:context, format:.hibc)
  let result = try parser.parseString("+A99912345/$$52001510X33")

  // We can either access the data from the raw JSON string...
  print(result.jsonString);

  // ... or from the fields dictionary...
  for (key, field) in result.fieldsByName {
    print("\(key) name: \(field.name)")
    print("\(key) raw: \(field.rawString)")
    if let parsed = field.parsed {
      // Here we just print the description of the object.
      // You should most likely check the type and cast it in order to safely use it.
      print("\(key) parsed: \(parsed.debugDescription)")
    }
  }

  // ... or from the fields array.
  for field in result.fields {
    print("\(field.name) raw: \(field.rawString)")
    if let parsed = field.parsed {
      print("\(field.name) parsed: \(parsed.debugDescription)")
    }
  }
} catch {
  // Something went wrong. Look at error for more info.
  print(error.localizedDescription)
}

For details, go to the API docs.

Format-Specific Documentation#