Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xremix/swiftgs1barcode

A GS1 Barcode Library and Parser in Swift
https://github.com/xremix/swiftgs1barcode

barcode barcode-api cocoapods gs1 ios swift

Last synced: 3 months ago
JSON representation

A GS1 Barcode Library and Parser in Swift

Awesome Lists containing this project

README

        

# SwiftGS1Barcode
A GS1 Barcode Library and Parser written in Swift

[![Badge w/ Version](https://cocoapod-badges.herokuapp.com/v/SwiftGS1Barcode/badge.png)](https://cocoadocs.org/docsets/SwiftGS1Barcode)
[![Language](https://img.shields.io/badge/language-swift%205-1b7cb9.svg)](https://img.shields.io/badge/language-swift%205-1b7cb9.svg)
[![iOS](https://img.shields.io/badge/iOS-8.0%2B-1b7cb9.svg)](https://img.shields.io/badge/iOS-9.0%2B-1b7cb9.svg)
[![macOS](https://img.shields.io/badge/macOS-Yes-1b7cb9.svg)](https://img.shields.io/badge/iOS-9.0%2B-1b7cb9.svg)
[![Linux](https://img.shields.io/badge/Linux-Yes-1b7cb9.svg)](https://img.shields.io/badge/iOS-9.0%2B-1b7cb9.svg)
[![Code Coverage](https://img.shields.io/badge/Code%20Coverage-97%25-green.svg)](https://img.shields.io/badge/Code%20Coverage-97%25-green.svg)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/xremix/SwiftGS1Barcode/master/LICENSE)
[![Build Status](https://travis-ci.org/xremix/SwiftGS1Barcode.svg?branch=master)](https://travis-ci.org/xremix/SwiftGS1Barcode)

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](https://cocoapods.org/pods/SwiftGS1Barcode) or can use Swift Package Manager.

**CocoaPods** currently might be out of date. Please compare with latest version of the git tags.

## Getting started
Parsing is as simple as

```Swift
import SwiftGS1Barcode
// ...
let gs1Barcode = "01101234670417283002\u{1D}1721103110S123456"
let barcode = GS1Barcode(raw: gs1Barcode)
barcode.validate() // To check if you barcode is valid

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

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

To parse **custom Application Identifiers** use the following code

```Swift
import SwiftGS1Barcode
// ...
let gs1BarcodeText = "90HelloWorld\u{1D}01101234670417283002\u{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](https://github.com/xremix/SwiftGS1Barcode/blob/master/SwiftGS1Barcode/GS1Barcode.swift#L19)

### Available Properties
The following properties are currently supported:

| ID | Application Identifier | Experimental Support |
|----|:-------------:|:-------------:|
| 00 | serialShippingContainerCode | No |
| 01 | gtin | No |
| 02 | gtinOfContainedTradeItems | No |
| 10 | lotNumber | No |
| 11 | productionDate | No |
| 12 | dueDate | No |
| 13 | packagingDate | No |
| 15 | bestBeforeDate | No |
| 17 | expirationDate | No |
| 20 | productVariant | No |
| 21 | serialNumber | No |
| 22 | secondaryDataFields | No |
| 30 | countOfItems | No |
| 37 | numberOfUnitsContained | No |
| 310 | productWeightInKg | No |
| 240 | additionalProductIdentification | No |
| 241 | customerPartNumber | No |
| 242 | madeToOrderVariationNumber | No |
| 250 | secondarySerialNumber | No |
| 251 | referenceToSourceEntity | No |
| 392 | priceSingleMonetaryArea | No |
| 393 | priceAndISO | No |
| 395 | pricePerUOM | No |
| 422 | countryOfOrigin | No |
| 714 | nhrnAIM | No |

*Experimental Support means that these are getting parsed, but there are no getter for this. You can get the value by calling e.g.* `myGs1Barcode.applicationIdentifiers["additionalProductIdentification"]`. *Also the implementation can change if any parsing issues come up.*

You can add custom application identifiers by adding them to the key / value dictionary:
```Swift
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](https://github.com/xremix/SwiftGS1Barcode/issues/new) if there is something missing for you.

## Installation

### Swift Package Manager (recommended)

Open your project and Xcode and click *File -> Swift Packages -> Add Package Dependency* and enter `[email protected]:xremix/SwiftGS1Barcode.git`

### CocoaPods
You can install [the library](https://cocoapods.org/pods/SwiftGS1Barcode) to your project by using [CocoaPods](https://cocoapods.org). 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](https://ga-beacon.appspot.com/UA-40522413-9/SwiftGS1Barcode/readme?pixel)