GS1Encoder
public class GS1Encoder
Main class for processing GS1 barcode data, including validation, format conversion, and generation of outputs such as GS1 Digital Link URIs and Human-Readable Interpretation text.
-
Recognised GS1 barcode formats (“symbologies”) for processing scan data.
This enum defines all supported GS1 barcode symbology types that can be used with the encoder. Each symbology has specific characteristics and use cases.
See moreDeclaration
Swift
public enum Symbology : Int32 -
Optional AI validation procedures that may be applied to detect invalid inputs.
These validation procedures are applied when AI data is provided using
setAIdataStr(_:),setDataStr(_:)orsetScanData(_:).See moreNote
Some validation procedures are “locked” (always enabled and cannot be modified). All validation procedures are listed to maintain correct enum value alignment with the native library.Declaration
Swift
public enum Validation : UInt32 -
Initialises a new instance of the GS1Encoder class.
Throws
GS1EncoderError.generalErrorif the library fails to initialiseDeclaration
Swift
public init() throws -
Release library resources.
This method will release the resources allocated by the native library. After calling this method, the GS1Encoder instance should not be used.
Declaration
Swift
public func free() -
Get the version string of the library.
Returns a string containing the version of the library, typically the build date.
Declaration
Swift
public func getVersion() -> StringReturn Value
The version of the library
-
Get the current symbology type.
This might be set manually via
setSym(_:)or automatically when processing scan data withsetScanData(_:).See also
setSym(_:)See also
SymbologySee also
setScanData(_:)Declaration
Swift
public func getSym() -> SymbologyReturn Value
The current symbology type
-
Set the symbology type.
This allows the symbology to be specified as any one of the
Symbologytypes.Throws
GS1EncoderError.parameterErrorif an invalid symbology type is providedSee also
getSym()See also
SymbologyDeclaration
Swift
public func setSym(_ value: Symbology) throwsParameters
valueThe symbology type to set
-
Get the current status of the “add check digit” mode for EAN/UPC and GS1 DataBar symbols.
See also
setAddCheckDigit(_:)Declaration
Swift
public func getAddCheckDigit() -> BoolReturn Value
trueif check digits will be generated automatically;falseif the data must include a valid check digit -
Enable or disable “add check digit” mode for EAN/UPC and GS1 DataBar symbols.
If
false(default), then the data string must contain a valid check digit. Iftrue, then the data string must not contain a check digit as one will be generated automatically.This option is only valid for symbologies that accept fixed-length data, specifically EAN/UPC and GS1 DataBar except Expanded (Stacked).
Throws
GS1EncoderError.parameterErrorif the value is invalidSee also
getAddCheckDigit()Declaration
Swift
public func setAddCheckDigit(_ value: Bool) throwsParameters
valuetrueto enable automatic check digit generation;falseto require check digit in data -
Get the status of the “include data titles in HRI” flag.
Returns
trueif data titles should be included in HRI; otherwisefalse.Declaration
Swift
public func getIncludeDataTitlesInHRI() -> BoolReturn Value
The status of the “include data titles in HRI” flag
-
Set the “include data titles in HRI” flag.
When set to
true, data titles from the GS1 General Specification will be included in the HRI text.Default:
falseThrows
GS1EncoderError.parameterErrorif an error occursDeclaration
Swift
public func setIncludeDataTitlesInHRI(_ value: Bool) throwsParameters
valuetrueto include data titles in HRI;falseotherwise -
Get the status of the “permit unknown AIs” mode.
Returns
trueif unknown AIs are permitted; otherwisefalse.Declaration
Swift
public func getPermitUnknownAIs() -> BoolReturn Value
The status of the “permit unknown AIs” mode
-
Set the “permit unknown AIs” mode.
When set to
true, AIs that are not recognised by the library will not be rejected. This can be useful when processing AIs that are not yet supported by the library.Default:
falseThrows
GS1EncoderError.parameterErrorif an error occursDeclaration
Swift
public func setPermitUnknownAIs(_ value: Bool) throwsParameters
valuetrueto permit unknown AIs;falseto reject them -
Get the status of the “permit zero-suppressed GTIN in GS1 DL URIs” mode.
Returns
trueif zero-suppressed GTINs are permitted in Digital Link URIs; otherwisefalse.Declaration
Swift
public func getPermitZeroSuppressedGTINinDLuris() -> BoolReturn Value
The status of the “permit zero-suppressed GTIN in GS1 DL URIs” mode
-
Set the status of the “permit zero-suppressed GTIN in GS1 DL URIs” mode.
When set to
true, zero-suppressed GTINs (such as GTIN-8, GTIN-12, GTIN-13) will be permitted in Digital Link URIs. Whenfalse, GTINs must be expressed in their canonical GTIN-14 form.Default:
falseThrows
GS1EncoderError.parameterErrorif an error occursDeclaration
Swift
public func setPermitZeroSuppressedGTINinDLuris(_ value: Bool) throwsParameters
valuetrueto permit zero-suppressed GTINs;falseto require canonical form -
Get whether a specific validation procedure is enabled.
See also
ValidationDeclaration
Swift
public func getValidationEnabled(_ validation: Validation) -> BoolParameters
validationThe validation procedure to query
Return Value
trueif the validation is enabled;falseotherwise -
Enable or disable a specific validation procedure.
Validation procedures can be selectively enabled or disabled to control which checks are applied to AI data.
Throws
GS1EncoderError.parameterErrorif the validation cannot be changed (e.g., it is locked)See also
getValidationEnabled(_:)See also
ValidationDeclaration
Swift
public func setValidationEnabled(validation: Validation, enabled: Bool) throwsParameters
validationThe validation procedure to configure
enabledtrueto enable the validation;falseto disable it -
Get the “validate AI associations” flag.
Returns
trueif mandatory associations between AIs are being validated; otherwisefalse.Declaration
Swift
@available(*, deprecated, message: "Use getValidationEnabled(_:﹚ with Validation.RequisiteAIs instead") public func getValidateAIassociations() -> BoolReturn Value
The status of the “validate AI associations” flag
-
Set the “validate AI associations” flag.
When set to
true, the library will check for mandatory associations between AIs.Throws
GS1EncoderError.parameterErrorif an error occursDeclaration
Swift
@available(*, deprecated, message: "Use setValidationEnabled(validation:enabled:﹚ with Validation.RequisiteAIs instead") public func setValidateAIassociations(_ value: Bool) throwsParameters
valuetrueto enable validation of AI associations;falseto disable -
Get the raw barcode message data.
The data string represents the raw message that would be encoded in a barcode symbol, using a harmonised format where FNC1 characters are represented by
^.See also
setDataStr(_:)Declaration
Swift
public func getDataStr() -> StringReturn Value
The barcode message data
-
Set the raw barcode message data.
This accepts barcode message data in a harmonised format where:
- A leading
^indicates GS1 Application Identifier syntax data A
^at any other position represents an FNC1 separator character
Throws
GS1EncoderError.parameterErrorif the data is invalidSee also
Declaration
Swift
public func setDataStr(_ value: String) throwsParameters
valueThe barcode message data to set
- A leading
-
Get the AI data as a bracketed AI element string.
Returns the AI data in human-friendly format using numerical AIs in brackets, e.g.,
(01)12345678901231(10)ABC123.See also
setAIdataStr(_:)Declaration
Swift
public func getAIdataStr() -> String?Return Value
The bracketed AI element string, or
nilif no AI data is available -
Set the AI data using a bracketed AI element string.
This accepts AI data in human-friendly format using numerical AIs in brackets, e.g.,
(01)12345678901231(10)ABC123.Throws
GS1EncoderError.parameterErrorif the data is invalidSee also
getAIdataStr()Declaration
Swift
public func setAIdataStr(_ value: String) throwsParameters
valueThe bracketed AI element string
-
Get the scan data.
Returns the scan data in the format that would be output by a barcode reader with AIM Symbology Identifiers enabled.
See also
setScanData(_:)Declaration
Swift
public func getScanData() -> StringReturn Value
The scan data
-
Set the scan data.
This accepts scan data in the format that would be output by a barcode reader with AIM Symbology Identifiers enabled. The symbology is extracted from the AIM Symbology Identifier and the AI data is extracted from the message.
Throws
GS1EncoderError.scanDataErrorif the scan data is invalidNote
Requires that AIM Symbology Identifiers are enabled on the barcode reader, and that any embedded FNC1 separator characters are represented by GS characters (ASCII 29)See also
getScanData()See also
getSym()Declaration
Swift
public func setScanData(_ value: String) throwsParameters
valueThe scan data to process
-
Get the error markup generated when parsing AI data fails due to a linting failure.
When a setter function throws an error due to invalid AI-based data, a marked up instance of the AI that failed will be generated. Where it is meaningful to identify offending characters in the input data, these characters will be surrounded by
|characters. Otherwise the entire AI value will be surrounded by|characters.Declaration
Swift
public func getErrMarkup() -> StringReturn Value
The error markup showing the location of the error in the input data
-
Get a GS1 Digital Link URI that represents the AI-based input data.
This generates a GS1 Digital Link URI from the current AI data. An optional stem can be provided to specify the domain and path prefix for the URI.
Throws
GS1EncoderError.digitalLinkErrorif the Digital Link URI cannot be generatedNote
AI data must be set usingsetAIdataStr(_:),setDataStr(_:)orsetScanData(_:)before calling this methodDeclaration
Swift
public func getDLuri(_ stem: String? = nil) throws -> StringParameters
stemOptional URI stem (e.g.,
https://example.com/). If not provided, a default stem is usedReturn Value
The GS1 Digital Link URI
-
Get the Human-Readable Interpretation (HRI) text for the current AI data as an array of strings.
The HRI provides a human-friendly representation of the AI data, with each array element representing a separate line of text. If data titles are enabled via
setIncludeDataTitlesInHRI(_:), they will be included in the output.See also
setIncludeDataTitlesInHRI(_:)Declaration
Swift
public func getHRI() -> Array<String>Return Value
Array of strings representing the HRI text lines
-
Get the non-numeric (ignored) query parameters from a GS1 Digital Link URI as an array of strings.
When a GS1 Digital Link URI is processed via
setScanData(_:), any non-numeric query parameters (those not representing AI data) are extracted and made available through this method.See also
setScanData(_:)Declaration
Swift
public func getDLignoredQueryParams() -> Array<String>Return Value
Array of strings representing the ignored query parameters
View on GitHub
Install in Dash