Skip to content

Commit ba8df4b

Browse files
committed
cleanup
1 parent 0e3e4b7 commit ba8df4b

8 files changed

Lines changed: 95 additions & 94 deletions

File tree

CDCodabarEncoder.swift

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ import Foundation
4343

4444
*********************************************************************/
4545

46-
public struct CDCodabarEncoder {
46+
struct CDCodabarEncoder {
4747

48-
private struct Constants {
48+
private enum Constants {
4949

50-
static let minLength = 3
51-
static let maxLength = 16
50+
enum Length {
51+
static let min = 3
52+
static let max = 16
53+
}
5254

5355
static let encodings: [Character: [Int]] = [
5456
"0": [1, 0, 1, 0, 1, 0, 0, 1, 1],
@@ -75,32 +77,31 @@ public struct CDCodabarEncoder {
7577
}
7678

7779
enum Error: Swift.Error {
78-
79-
case invalidLength
80-
case invalidStartCharacter
81-
case invalidEndCharacter
82-
case invalidIntermediateCharacter
80+
case length
81+
case startCharacter
82+
case endCharacter
83+
case intermediateCharacter
8384
}
8485

8586
private let code: String
8687

8788
public init(code: String) throws {
8889
let code = code.uppercased()
8990

90-
guard (Constants.minLength ... Constants.maxLength) ~= code.characters.count else {
91-
throw Error.invalidLength
91+
guard (Constants.Length.min ... Constants.Length.max) ~= code.count else {
92+
throw Error.length
9293
}
9394

94-
guard let startChar = code.characters.first, ("A" ... "D") ~= startChar else {
95-
throw Error.invalidStartCharacter
95+
guard let startChar = code.first, ("A" ... "D") ~= startChar else {
96+
throw Error.startCharacter
9697
}
9798

98-
guard let stopChar = code.characters.last, ("A" ... "D") ~= stopChar else {
99-
throw Error.invalidEndCharacter
99+
guard let stopChar = code.last, ("A" ... "D") ~= stopChar else {
100+
throw Error.endCharacter
100101
}
101102

102-
guard code.characters.filter({ !Constants.encodings.keys.contains($0) }).isEmpty else {
103-
throw Error.invalidIntermediateCharacter
103+
guard code.filter({ !Constants.encodings.keys.contains($0) }).isEmpty else {
104+
throw Error.intermediateCharacter
104105
}
105106

106107
self.code = code
@@ -111,9 +112,9 @@ public struct CDCodabarEncoder {
111112
///
112113
/// - Returns: Returns array of integer representing bits
113114
public func sequence() -> [Int] {
114-
return code.characters
115+
return code
115116
.map { Constants.encodings[$0]! }
116117
.joined(separator: [0])
117-
.flatMap { $0 }
118+
.compactMap { $0 }
118119
}
119120
}

CDCodabarView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "CDCodabarView"
3-
s.version = "1.0.0"
3+
s.version = "1.1.0"
44
s.summary = "Codabar Barcode Generator for iOS."
55
s.homepage = "https://github.com/Coledunsby/CDCodabarView"
66
s.authors = { "Cole Dunsby" => "[email protected]" }

CDCodabarView.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
import UIKit
1010

1111
@IBDesignable
12-
public final class CDCodabarView: UIView {
12+
open class CDCodabarView: UIView {
1313

14+
// MARK: - Inspectable Properties
15+
1416
@IBInspectable public var barColor: UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) { didSet { setNeedsDisplay() }}
1517
@IBInspectable public var textColor: UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) { didSet { setNeedsDisplay() }}
1618
@IBInspectable public var padding: CGFloat = 2.0 { didSet { setNeedsDisplay() }}
1719
@IBInspectable public var hideCode: Bool = false { didSet { setNeedsDisplay() }}
20+
@IBInspectable public var invalidText: String = "Invalid Code" { didSet { setNeedsDisplay() }}
1821

1922
@IBInspectable public var code: String = "A123456789B" {
2023
didSet {
@@ -23,10 +26,16 @@ public final class CDCodabarView: UIView {
2326
}
2427
}
2528

29+
// MARK: - Public Properties
30+
2631
public var font = UIFont.systemFont(ofSize: 15.0) { didSet { setNeedsDisplay() }}
2732

33+
// MARK: - Private Properties
34+
2835
private var encoder: CDCodabarEncoder?
2936

37+
// MARK: - Lifecycle
38+
3039
override init(frame: CGRect) {
3140
super.init(frame: frame)
3241
}
@@ -35,27 +44,25 @@ public final class CDCodabarView: UIView {
3544
super.init(coder: aDecoder)
3645
}
3746

38-
override public func draw(_ rect: CGRect) {
47+
override open func draw(_ rect: CGRect) {
3948
let paragraphStyle = NSMutableParagraphStyle()
4049
paragraphStyle.alignment = .center
4150

4251
let attributes: [NSAttributedStringKey: Any] = [
43-
NSAttributedStringKey.font: font,
44-
NSAttributedStringKey.foregroundColor: textColor,
45-
NSAttributedStringKey.paragraphStyle: paragraphStyle,
52+
.font: font,
53+
.foregroundColor: textColor,
54+
.paragraphStyle: paragraphStyle
4655
]
4756

4857
guard let encoder = encoder else {
49-
let text = "Invalid Code"
50-
51-
let textSize = text.boundingRect(
58+
let textSize = invalidText.boundingRect(
5259
with: CGSize(width: bounds.size.width, height: CGFloat.greatestFiniteMagnitude),
5360
options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin],
54-
attributes: [NSAttributedStringKey.font: font],
61+
attributes: [.font: font],
5562
context: nil
5663
)
5764

58-
text.draw(
65+
invalidText.draw(
5966
at: CGPoint(x: bounds.size.width / 2 - textSize.width / 2, y: bounds.size.height / 2 - textSize.height / 2),
6067
withAttributes: attributes
6168
)

CDCodabarViewExample.xcodeproj/project.pbxproj

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
2092DBCB1E9BC13000B735A5 /* CDCodabarEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2092DBCA1E9BC13000B735A5 /* CDCodabarEncoder.swift */; };
11-
2092DBD31E9BC1B300B735A5 /* EncoderSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2092DBD21E9BC1B300B735A5 /* EncoderSpecs.swift */; };
11+
2092DBD31E9BC1B300B735A5 /* CDCodabarViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2092DBD21E9BC1B300B735A5 /* CDCodabarViewTests.swift */; };
1212
252518E51DD3BB9B00F770A3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 252518DF1DD3BB9B00F770A3 /* AppDelegate.swift */; };
1313
252518E61DD3BB9B00F770A3 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 252518E01DD3BB9B00F770A3 /* Images.xcassets */; };
1414
252518E81DD3BB9B00F770A3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 252518E21DD3BB9B00F770A3 /* LaunchScreen.storyboard */; };
@@ -30,7 +30,7 @@
3030
/* Begin PBXFileReference section */
3131
2092DBCA1E9BC13000B735A5 /* CDCodabarEncoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDCodabarEncoder.swift; sourceTree = "<group>"; };
3232
2092DBD01E9BC1B300B735A5 /* CDCodabarViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CDCodabarViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
33-
2092DBD21E9BC1B300B735A5 /* EncoderSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncoderSpecs.swift; sourceTree = "<group>"; };
33+
2092DBD21E9BC1B300B735A5 /* CDCodabarViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CDCodabarViewTests.swift; sourceTree = "<group>"; };
3434
2092DBD41E9BC1B300B735A5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3535
252518DF1DD3BB9B00F770A3 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3636
252518E01DD3BB9B00F770A3 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
@@ -39,7 +39,8 @@
3939
252518E31DD3BB9B00F770A3 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
4040
252518E41DD3BB9B00F770A3 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
4141
252518ED1DD3BDDB00F770A3 /* CDCodabarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDCodabarView.swift; sourceTree = "<group>"; };
42-
607FACD01AFB9204008FA782 /* CDCodabarView_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CDCodabarView_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
42+
607FACD01AFB9204008FA782 /* CDCodabarViewExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CDCodabarViewExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
43+
EDEF7BA721014883002D4DCB /* CDCodabarView.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = CDCodabarView.podspec; sourceTree = "<group>"; };
4344
/* End PBXFileReference section */
4445

4546
/* Begin PBXFrameworksBuildPhase section */
@@ -63,7 +64,7 @@
6364
2092DBD11E9BC1B300B735A5 /* CDCodabarViewTests */ = {
6465
isa = PBXGroup;
6566
children = (
66-
2092DBD21E9BC1B300B735A5 /* EncoderSpecs.swift */,
67+
2092DBD21E9BC1B300B735A5 /* CDCodabarViewTests.swift */,
6768
2092DBD41E9BC1B300B735A5 /* Info.plist */,
6869
);
6970
path = CDCodabarViewTests;
@@ -85,6 +86,7 @@
8586
607FACC71AFB9204008FA782 = {
8687
isa = PBXGroup;
8788
children = (
89+
EDEF7BA721014883002D4DCB /* CDCodabarView.podspec */,
8890
252518ED1DD3BDDB00F770A3 /* CDCodabarView.swift */,
8991
2092DBCA1E9BC13000B735A5 /* CDCodabarEncoder.swift */,
9092
252518DE1DD3BB9B00F770A3 /* CDCodabarViewExample */,
@@ -96,7 +98,7 @@
9698
607FACD11AFB9204008FA782 /* Products */ = {
9799
isa = PBXGroup;
98100
children = (
99-
607FACD01AFB9204008FA782 /* CDCodabarView_Example.app */,
101+
607FACD01AFB9204008FA782 /* CDCodabarViewExample.app */,
100102
2092DBD01E9BC1B300B735A5 /* CDCodabarViewTests.xctest */,
101103
);
102104
name = Products;
@@ -123,9 +125,9 @@
123125
productReference = 2092DBD01E9BC1B300B735A5 /* CDCodabarViewTests.xctest */;
124126
productType = "com.apple.product-type.bundle.unit-test";
125127
};
126-
607FACCF1AFB9204008FA782 /* CDCodabarView_Example */ = {
128+
607FACCF1AFB9204008FA782 /* CDCodabarViewExample */ = {
127129
isa = PBXNativeTarget;
128-
buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarView_Example" */;
130+
buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarViewExample" */;
129131
buildPhases = (
130132
607FACCC1AFB9204008FA782 /* Sources */,
131133
607FACCD1AFB9204008FA782 /* Frameworks */,
@@ -135,9 +137,9 @@
135137
);
136138
dependencies = (
137139
);
138-
name = CDCodabarView_Example;
140+
name = CDCodabarViewExample;
139141
productName = CDCodabarView;
140-
productReference = 607FACD01AFB9204008FA782 /* CDCodabarView_Example.app */;
142+
productReference = 607FACD01AFB9204008FA782 /* CDCodabarViewExample.app */;
141143
productType = "com.apple.product-type.application";
142144
};
143145
/* End PBXNativeTarget section */
@@ -147,19 +149,19 @@
147149
isa = PBXProject;
148150
attributes = {
149151
LastSwiftUpdateCheck = 0830;
150-
LastUpgradeCheck = 0810;
152+
LastUpgradeCheck = 1000;
151153
ORGANIZATIONNAME = CocoaPods;
152154
TargetAttributes = {
153155
2092DBCF1E9BC1B300B735A5 = {
154156
CreatedOnToolsVersion = 8.3;
155-
DevelopmentTeam = B3YTJ78KXJ;
157+
DevelopmentTeam = W8W9HUZP5Z;
156158
LastSwiftMigration = 0940;
157159
ProvisioningStyle = Automatic;
158160
TestTargetID = 607FACCF1AFB9204008FA782;
159161
};
160162
607FACCF1AFB9204008FA782 = {
161163
CreatedOnToolsVersion = 6.3.1;
162-
DevelopmentTeam = JU6JS2KXPW;
164+
DevelopmentTeam = W8W9HUZP5Z;
163165
LastSwiftMigration = 0940;
164166
};
165167
};
@@ -177,7 +179,7 @@
177179
projectDirPath = "";
178180
projectRoot = "";
179181
targets = (
180-
607FACCF1AFB9204008FA782 /* CDCodabarView_Example */,
182+
607FACCF1AFB9204008FA782 /* CDCodabarViewExample */,
181183
2092DBCF1E9BC1B300B735A5 /* CDCodabarViewTests */,
182184
);
183185
};
@@ -208,7 +210,7 @@
208210
isa = PBXSourcesBuildPhase;
209211
buildActionMask = 2147483647;
210212
files = (
211-
2092DBD31E9BC1B300B735A5 /* EncoderSpecs.swift in Sources */,
213+
2092DBD31E9BC1B300B735A5 /* CDCodabarViewTests.swift in Sources */,
212214
);
213215
runOnlyForDeploymentPostprocessing = 0;
214216
};
@@ -228,7 +230,7 @@
228230
/* Begin PBXTargetDependency section */
229231
2092DBD61E9BC1B300B735A5 /* PBXTargetDependency */ = {
230232
isa = PBXTargetDependency;
231-
target = 607FACCF1AFB9204008FA782 /* CDCodabarView_Example */;
233+
target = 607FACCF1AFB9204008FA782 /* CDCodabarViewExample */;
232234
targetProxy = 2092DBD51E9BC1B300B735A5 /* PBXContainerItemProxy */;
233235
};
234236
/* End PBXTargetDependency section */
@@ -242,7 +244,7 @@
242244
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
243245
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
244246
DEBUG_INFORMATION_FORMAT = dwarf;
245-
DEVELOPMENT_TEAM = B3YTJ78KXJ;
247+
DEVELOPMENT_TEAM = W8W9HUZP5Z;
246248
INFOPLIST_FILE = CDCodabarViewTests/Info.plist;
247249
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
248250
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
@@ -251,7 +253,7 @@
251253
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
252254
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
253255
SWIFT_VERSION = 4.0;
254-
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarView_Example.app/CDCodabarView_Example";
256+
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarViewExample.app/CDCodabarViewExample";
255257
};
256258
name = Debug;
257259
};
@@ -262,15 +264,15 @@
262264
CLANG_ANALYZER_NONNULL = YES;
263265
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
264266
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
265-
DEVELOPMENT_TEAM = B3YTJ78KXJ;
267+
DEVELOPMENT_TEAM = W8W9HUZP5Z;
266268
INFOPLIST_FILE = CDCodabarViewTests/Info.plist;
267269
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
268270
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
269271
PRODUCT_BUNDLE_IDENTIFIER = com.appunite.CDCodabarViewTests;
270272
PRODUCT_NAME = "$(TARGET_NAME)";
271273
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
272274
SWIFT_VERSION = 4.0;
273-
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarView_Example.app/CDCodabarView_Example";
275+
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarViewExample.app/CDCodabarViewExample";
274276
};
275277
name = Release;
276278
};
@@ -282,14 +284,22 @@
282284
CLANG_CXX_LIBRARY = "libc++";
283285
CLANG_ENABLE_MODULES = YES;
284286
CLANG_ENABLE_OBJC_ARC = YES;
287+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
285288
CLANG_WARN_BOOL_CONVERSION = YES;
289+
CLANG_WARN_COMMA = YES;
286290
CLANG_WARN_CONSTANT_CONVERSION = YES;
291+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
287292
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
288293
CLANG_WARN_EMPTY_BODY = YES;
289294
CLANG_WARN_ENUM_CONVERSION = YES;
290295
CLANG_WARN_INFINITE_RECURSION = YES;
291296
CLANG_WARN_INT_CONVERSION = YES;
297+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
298+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
299+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
292300
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
301+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
302+
CLANG_WARN_STRICT_PROTOTYPES = YES;
293303
CLANG_WARN_SUSPICIOUS_MOVE = YES;
294304
CLANG_WARN_UNREACHABLE_CODE = YES;
295305
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -329,14 +339,22 @@
329339
CLANG_CXX_LIBRARY = "libc++";
330340
CLANG_ENABLE_MODULES = YES;
331341
CLANG_ENABLE_OBJC_ARC = YES;
342+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
332343
CLANG_WARN_BOOL_CONVERSION = YES;
344+
CLANG_WARN_COMMA = YES;
333345
CLANG_WARN_CONSTANT_CONVERSION = YES;
346+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
334347
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
335348
CLANG_WARN_EMPTY_BODY = YES;
336349
CLANG_WARN_ENUM_CONVERSION = YES;
337350
CLANG_WARN_INFINITE_RECURSION = YES;
338351
CLANG_WARN_INT_CONVERSION = YES;
352+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
353+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
354+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
339355
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
356+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
357+
CLANG_WARN_STRICT_PROTOTYPES = YES;
340358
CLANG_WARN_SUSPICIOUS_MOVE = YES;
341359
CLANG_WARN_UNREACHABLE_CODE = YES;
342360
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -365,7 +383,7 @@
365383
isa = XCBuildConfiguration;
366384
buildSettings = {
367385
CLANG_ENABLE_MODULES = YES;
368-
DEVELOPMENT_TEAM = JU6JS2KXPW;
386+
DEVELOPMENT_TEAM = W8W9HUZP5Z;
369387
INFOPLIST_FILE = "$(SRCROOT)/CDCodabarViewExample/Info.plist";
370388
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
371389
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -382,7 +400,7 @@
382400
isa = XCBuildConfiguration;
383401
buildSettings = {
384402
CLANG_ENABLE_MODULES = YES;
385-
DEVELOPMENT_TEAM = JU6JS2KXPW;
403+
DEVELOPMENT_TEAM = W8W9HUZP5Z;
386404
INFOPLIST_FILE = "$(SRCROOT)/CDCodabarViewExample/Info.plist";
387405
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
388406
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -415,7 +433,7 @@
415433
defaultConfigurationIsVisible = 0;
416434
defaultConfigurationName = Release;
417435
};
418-
607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarView_Example" */ = {
436+
607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarViewExample" */ = {
419437
isa = XCConfigurationList;
420438
buildConfigurations = (
421439
607FACF01AFB9204008FA782 /* Debug */,

0 commit comments

Comments
 (0)