Documentation for iOS

Usage Sample

The following code shows typical usage of the parser library.

#import <ScanditParser/ScanditParser.h>

...

// Replace SPLDataFormatHIBC with the data format of your choice.
SPLParser *parser = [[SPLParser alloc] initWithDataFormat:SPLDataFormatHIBC];
NSError *err;
SPLParserResult *result = [parser parseString:@"+A99912345/$$52001510X33" error:&err];
if (!result) {
    // Something went wrong. Look at err for more info.
}

// We can either access the data from the raw JSON string...
NSLog(@"%@", result.jsonString);

// ... or from the fields dictionary...
NSDictionary<NSString*, SPLField*> *fieldsDictionary = result.fieldsDict;
for (NSString *key in fieldsDictionary.allKeys) {
    SPLField *field = [fieldsDictionary objectForKey:key];
    NSLog(@"%@ name: %@", key, field.name);
    NSLog(@"%@ raw: %@", key, field.rawString);
    NSLog(@"%@ parsed: %@", key, field.parsed);
}

// ... or from the fields array
for (SPLField* field in result.fieldsArray) {
    NSLog(@"%@ raw: %@", field.name, field.rawString);
    NSLog(@"%@ parsed: %@", field.name, field.parsed);
}

iOS API

class SPLParser

Defines the interface for a data string parser. Parsers are capable of parsing one particular data format, which is passed to them during construction.

initWithDataFormat:(SPLDataFormat)format

The parser type can be SPLDataFormatHIBC, SPLDataFormatGS1AI or SPLDataFormatDLID.

Returns:The parser capable of parsing data of the provided format.
Return type:SPLParser*
parseString:(NSString *)string error:(NSError **)outError;

Parses the data string and returns the contained fields in the result object. In case the result could not be parsed, the error message is accessible as part of the outError parameter.

Returns:

The result object. Before accessing the fields of the result, you must ensure that the string was correctly parsed, that is, outError has not been set.

Parameters:
  • string – The string to parse. Must not be nil.
  • outError – Upon failure will be set to an instance of NSError containing details on why the data could not be parsed. Can be nil.
Return type:

SPLParserResult*

parseRawData:(NSString *)rawData error:(NSError **)outError;

Parses the raw data of the code and returns the contained fields in the result object. In case the result could not be parsed, the error message is accessible as part of the outError parameter.

Returns:

The result object. Before accessing the fields of the result, you must ensure that the string was correctly parsed, that is, outError has not been set.

Parameters:
  • rawData – The raw data of the string to parse. Must not be nil.
  • outError – Upon failure will be set to an instance of NSError containing details on why the data could not be parsed. Can be nil.
Return type:

SPLParserResult*

class SPLParserResult

The SPLParserResult holds the result of a successfully parsed data string. The result is a collection of fields that can either be accessed as an sequential array (fieldsArray), or a dictionary (fieldsDict) which maps field name onto values.

json

The JSON string of the result content.

Type:NSString*
fieldsDict

Dictionary of SPLField objects with key being the field name.

Type:NSDictionary<NSString*, SPLField*>*
fieldsArray

Array of SPLField objects with key being the field name. Use this accessor if the order of the fields in the string matter, if you are only interested in a particular field, using the SPLField.fieldsDict is simpler.

Type:NSArray<SPLField*>*
class SPLField

A particular field of the parsed result.

name

The name of the field.

Type:NSString*

This attribute corresponds to the JSON “name” field.

rawString

Raw substring of the original code containing the field data. For fields that are inferred and do not have a direct correspondence to a particular part of the string, the string is set to an empty string. An example of such a field is the Metadata field field of HIBC codes.

Type:NSString*

This attribute corresponds to the JSON “rawString” field.

parsed

The parsed representation of the data contained in this field. If no parsed representation is available for the field, this property is nil. Use SPLField.rawString to retrieve the data for these fields.

Type:id. Depending on the field, this may be an instance of NSNumber, NSDictionary, NSArray, or NSString.

This attribute corresponds to the JSON “parsed” field.