Latest 0.4.1
Homepage https://github.com/xremix/SwiftGS1Barcode
License MIT
Platforms ios 8.0
Authors

A GS1 Barcode Library and Parser written in Swift

Badge w/ Version
Language
iOS
Code Coverage
GitHub license
Build Status

A Library to parse GS1 Barcode strings into a object and allows an easy access to the properties that a GS1 Barcode can have.
Supported is a large set of common Application Identifiers (GS1 Barcodes), but it can be easily extended on the fly to support any identifier needed.

Contributions are most welcome.

You can also find this project on CocoaPods

Getting started

Parsing is as simple as

import SwiftGS1Barcode
// ...
let gs1Barcode = "01101234670417283002u{1D}1721103110S123456"
let barcode = GS1Barcode(raw: gs1Barcode)

print(barcode.gtin) // 10123467041728
print(barcode.countOfItems) // 2
print(barcode.expirationDate) // 31.10.2021
print(barcode.lotNumber) // S123456

Advanced Usage

To seperate the parsing from initializing I’d recommend a code like

import SwiftGS1Barcode
// ...
let gs1BarcodeText = "01101234670417283002u{1D}1721103110S123456"
let barcode = GS1Barcode()
barcode.raw = gs1BarcodeText
_ = barcode.parse()

To parse custom Application Identifiers use the following code

import SwiftGS1Barcode
// ...
let gs1BarcodeText = "90HelloWorldu{1D}01101234670417283002u{1D}1721103110S123456"
let barcode = GS1Barcode()
barcode.applicationIdentifiers["custom1"] = GS1ApplicationIdentifier("90", length: 30, type: .String, dynamicLength: true)
barcode.raw = gs1BarcodeText
_ = barcode.parse()
print(barcode.applicationIdentifiers["custom1"]!.stringValue)

To see some samples, of how to set up Application Identifiers check out the GS1Barcode Class

Available Properties

!Attention! Currently only the following properties are available and do get parsed

Application Identifier ID
serialShippingContainerCode 00
gtin 01
gtinOfContainedTradeItems 02
lotNumber (batchNumber) 10
productionDate 11
dueDate 12
packagingDate 13
bestBeforeDate 15
expirationDate 17
productVariant 20
serialNumber 21
secondaryDataFields 22
countOfItems 30
numberOfUnitsContained 37

Experimental Support for lotNumberN, additionalProductIdentification, customerPartNumber, madeToOrderVariationNumber, secondarySerialNumber, referenceToSourceEntity, productWeightInKgNoDecimal, productWeightInKgOnceDecimal, productWeightInKgTwoDecimal

You can add custom application identifiers by adding them to the key / value dictionary:

let barcode = GS1Barcode()
barcode.applicationIdentifiers["custom1"] = GS1ApplicationIdentifier("90", length: 30, type: .String, dynamicLength: true)

They’ll automatically get parsed by the parse() function.
You can also simply contribute by yourself and add them to the GS1BarcodeParser.swift class, or open an issue if there is something missing for you.

Installation

CocoaPods

You can install the library to your project by using CocoaPods. Add the following code to your Podfile:

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
    pod 'SwiftGS1Barcode'
end

Alternative you can also add the direct Github source (or a different branch):

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
    pod 'SwiftGS1Barcode', :git => 'https://github.com/xremix/SwiftGS1Barcode', :branch => 'master'
end

Manually

You can add the project as a git submodule. Simply drag the SwiftGS1Barcode.xcodeproj file into your Xcode project.
Don’t forget to add the framework in your application target

Resources

A couple of resources, used for this project.

GS1 parsing

https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf
https://www.activebarcode.de/codes/ean128_ucc128_ai.html
https://www.gs1.at/fileadmin/user_upload/Liste_GS1_Austria_Application_Identifier.pdf

CocoaPod

https://www.appcoda.com/cocoapods-making-guide/

Analytics

Latest podspec

{
    "name": "SwiftGS1Barcode",
    "version": "0.4.1",
    "summary": "A GS1 Barcode Library and Parser for Swift",
    "description": "A GS1 Barcode Library and Parser for Swift. It allows to pass strings and validate these as well as get the GS1 tags.",
    "homepage": "https://github.com/xremix/SwiftGS1Barcode",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Toni Hoffmann": "[email protected]"
    },
    "source": {
        "git": "https://github.com/xremix/SwiftGS1Barcode.git",
        "tag": "0.4.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "SwiftGS1Barcode/*.swift"
}

Pin It on Pinterest

Share This