Label Definition

Defined in framework ScanditLabelCapture

LabelDefinition
open class LabelDefinition : NSObject

Added in version 6.21.0

A configuration that defines labels and their relevant fields for Smart Label Capture to recognize and extract during scans. Label definitions provide flexible data extraction from specific label layouts without custom coding, enabling structured data extraction from diverse label types.

Label definitions support two primary approaches:

  • Pre-built Labels - Includes predefined configurations for common label types (price labels, VIN labels, 7-segment displays)

  • Custom Labels - Allows creating unique label definitions using custom barcode and text fields

Key configuration options for custom fields:

  • valueRegexes - Regular expressions to identify target strings

  • anchorRegexes - Context-identifying keywords for field recognition

  • symbologies - Specific barcode types to match

  • isOptional - Determines field requirement status

Pre-built field categories include:

  • Barcode Fields - Serial number, part number, IMEI

  • Price/Weight Fields - Unit price, total price, weight

  • Date/Text Fields - Packing date, expiry date

You can create label definitions in three ways:

  • Factory Methods - Use predefined definitions like priceCapture() for common use cases

  • Builder Pattern - Use Swift’s result builder pattern for fluent configuration

  • Manual Construction - Create with explicit field lists using init()

Here is an example of how to use the builder pattern to create a label definition:

LabelDefinition("weighted_definition") {
      CustomBarcode(
          name: "barcode",
          symbologies: [.ean13UPCA, .gs1DatabarExpanded, .code128]
      )

      ExpiryDateText(name: "expiry_date")
          .labelDateFormat(
              LabelDateFormat(
                  componentFormat: LabelDateComponentFormat.MDY,
                  acceptPartialDates: false
              )
          )
          .optional(true)

      WeightText(name: "weight")
          .optional(true)

      UnitPriceText(name: "unit_price")
          .optional(true)
  }
init
init(name: String, fields: Array<LabelFieldDefinition>?)

Added in version 6.21.0

Create a new label definition with the given name and fields.

name
open var name: String { get }

Added in version 6.21.0

The name of the label definition.

fields
open var fields: Array<LabelFieldDefinition> { get }

Added in version 6.21.0

The fields of the label definition.

hiddenProperties
open var hiddenProperties: Dictionary<AnyHashable, Any> { get, set }

Added in version 6.21.0

Set properties to the label definition.

adaptiveRecognitionMode
open var adaptiveRecognitionMode: AdaptiveRecognitionMode { get, set }

Added in version 8.0.0

Controls whether the Adaptive Recognition Engine is enabled for this label definition. The Adaptive Recognition Engine helps making Smart Label Capture more robust and scalable thanks to its larger, more capable model hosted in the cloud. Whenever Smart Label Capture’s on-device model fails to capture data, the SDK will automatically trigger the Adaptive Recognition Engine to capture complex, unforeseen data capture and process it with high accuracy and reliability. See AdaptiveRecognitionMode for available options. Defaults to AdaptiveRecognitionMode.off.

vinLabelDefinition
open class func vinLabelDefinition(withName name: String) -> Self

Added in version 7.4.0

Creates a predefined label definition for scanning Vehicle Identification Numbers (VIN). VIN codes are 17-character alphanumeric serial numbers that can appear as either text or barcodes on vehicles.

let vinLabel = LabelDefinition.vinLabelDefinition(withName: "vehicle_vin")

This factory method returns a label definition with two optional fields:

  • text - An optional text field for scanning VIN codes in text format with pattern [A-Z0-9]{17}

  • barcode - An optional barcode field for scanning VIN codes in barcode format (QR, Code 39, or Data Matrix symbologies) with pattern [A-Z0-9]{17}

priceCapture
open class func priceCapture(withName name: String) -> Self

Added in version 7.4.0

Creates a predefined label definition for scanning price labels on retail products. This factory method is designed for price checking scenarios where both barcode and price text need to be captured from product labels.

This factory method returns a label definition with two fields:

  • SKU - A mandatory barcode field for scanning Symbology.ean13UPCA and Symbology.code128.

  • priceText - An optional text field for scanning price text using specialized price label recognition with pattern \\d+.

You can easily disable one of the symbologies of the barcode field by changing global mode settings. For example, to disable Symbology.code128 one can do this:

let symbologySettings = labelCaptureSettings.settings(for: .code128)
symbologySettings.isEnabled = false

Note

To use this label definition, make sure to import the PriceCapture library.

sevenSegmentDisplay
open class func sevenSegmentDisplay(withName name: String) -> Self

Added in version 7.5.0

Creates a predefined label definition for reading numeric values from 7-segment displays, such as digital scales, meters, or other electronic displays.

This factory method returns a label definition with one field:

  • weight - A text field for 7-segment displays with pattern [0-9OQB]{1,4}[\.\,\s]?[0-9OQB]{1,4}

The pattern accounts for common variations in 7-segment displays where certain characters may appear similar (e.g., ‘O’ for ‘0’, ‘Q’ for ‘0’, ‘B’ for ‘8’).

addField
open func addField(_ field: LabelFieldDefinition) -> Void

Added in version 6.20.0

Add a field to the label definition.

addFields
open func addFields(_ fields: Array<LabelFieldDefinition>) -> Void

Added in version 6.20.0

Add multiple fields to the label definition.