Skip to content

Commit

Permalink
make application identifiers extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
xremix committed Jun 27, 2017
1 parent 5250113 commit bc66574
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@ print(barcode.amount) // 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
let gs1BarcodeText = "01101234670417283002\u{1D}1721103110S123456"
let barcode = GS1Barcode()
barcode.raw = gs1BarcodeText
_ = barcode.parse()
```

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

```Swift
let gs1BarcodeText = "90HalloWelt\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)
```

### Available Properties
**!Attention!** Currently only the following properties are available and do get parsed

Expand Down
2 changes: 1 addition & 1 deletion SwiftGS1Barcode.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SwiftGS1Barcode'
s.version = '0.3.0'
s.version = '0.3.1'
s.summary = 'A GS1 Barcode Library and Parser for Swift'

s.description = <<-DESC
Expand Down
4 changes: 4 additions & 0 deletions SwiftGS1Barcode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
6413187C1F023B0700F9C4DF /* GS1BarcodeAdvancedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6413187B1F023B0700F9C4DF /* GS1BarcodeAdvancedTests.swift */; };
64754CFE1F010A1000B22B62 /* GS1Barcode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754CFD1F010A1000B22B62 /* GS1Barcode.swift */; };
64754D001F010E8400B22B62 /* BarcodeParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754CFF1F010E8400B22B62 /* BarcodeParser.swift */; };
64754D021F010E9100B22B62 /* Barcode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D011F010E9100B22B62 /* Barcode.swift */; };
Expand Down Expand Up @@ -37,6 +38,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
6413187B1F023B0700F9C4DF /* GS1BarcodeAdvancedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GS1BarcodeAdvancedTests.swift; sourceTree = "<group>"; };
64754CFD1F010A1000B22B62 /* GS1Barcode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GS1Barcode.swift; sourceTree = "<group>"; };
64754CFF1F010E8400B22B62 /* BarcodeParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarcodeParser.swift; sourceTree = "<group>"; };
64754D011F010E9100B22B62 /* Barcode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Barcode.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -126,6 +128,7 @@
64754D0F1F01106500B22B62 /* SimpleBarcodeTests.swift */,
64754D131F01107500B22B62 /* StringTests.swift */,
E28E99881F01ABC50093C02B /* GS1BarcodeNodeTests.swift */,
6413187B1F023B0700F9C4DF /* GS1BarcodeAdvancedTests.swift */,
);
path = SwiftGS1BarcodeTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -262,6 +265,7 @@
64754D141F01107500B22B62 /* StringTests.swift in Sources */,
64754D0C1F01103C00B22B62 /* BarcodeParserTests.swift in Sources */,
E28E99891F01ABC50093C02B /* GS1BarcodeNodeTests.swift in Sources */,
6413187C1F023B0700F9C4DF /* GS1BarcodeAdvancedTests.swift in Sources */,
64DD17381F014F8700F10103 /* GS1ApplicationIdentifierTests.swift in Sources */,
64754D121F01106D00B22B62 /* GS1BarcodeTests.swift in Sources */,
64754D101F01106500B22B62 /* SimpleBarcodeTests.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion SwiftGS1Barcode/GS1ApplicationIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum GS1ApplicationIdentifierType: String{
}
}

class GS1ApplicationIdentifier: NSObject{
public class GS1ApplicationIdentifier: NSObject{
var identifier: String
var maxLength: Int
var dynamicLength: Bool = false
Expand Down
2 changes: 1 addition & 1 deletion SwiftGS1Barcode/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.3.0</string>
<string>0.3.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
37 changes: 37 additions & 0 deletions SwiftGS1BarcodeTests/GS1BarcodeAdvancedTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// GS1BarcodeAdvancedTests.swift
// SwiftGS1Barcode
//
// Created by Toni Hoffmann on 27.06.17.
// Copyright © 2017 Toni Hoffmann. All rights reserved.
//

import XCTest

@testable import SwiftGS1Barcode

class GS1BarcodeAdvancedTests: XCTestCase {

func testParseLater(){
let gs1BarcodeText = "01101234670417283002\u{1D}1721103110S123456"
let barcode = GS1Barcode()
barcode.raw = gs1BarcodeText
_ = barcode.parse()

XCTAssert(barcode.validate())
}

func testAddApplicationIdentifier(){
let gs1BarcodeText = "90HalloWelt\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)

XCTAssert(barcode.validate())
XCTAssertEqual(barcode.applicationIdentifiers["custom1"]!.stringValue, "HalloWelt")

}

}
9 changes: 0 additions & 9 deletions SwiftGS1BarcodeTests/GS1BarcodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,6 @@ class GS1BarcodeTests: XCTestCase {
XCTAssertFalse(b.validate())
}

func testParseLater(){
let gs1BarcodeText = "01101234670417283002\u{1D}1721103110S123456"
let barcode = GS1Barcode()
barcode.raw = gs1BarcodeText
_ = barcode.parse()

XCTAssert(barcode.validate())
}

func testPerformance(){

measure {
Expand Down

0 comments on commit bc66574

Please sign in to comment.