Skip to content

Commit 0e3e4b7

Browse files
authored
Merge pull request #4 from USThing/swift-4
Upgrade to swift 4 and fix related issues
2 parents 6cb6d52 + 7ee2538 commit 0e3e4b7

4 files changed

Lines changed: 35 additions & 20 deletions

File tree

CDCodabarView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public final class CDCodabarView: UIView {
3939
let paragraphStyle = NSMutableParagraphStyle()
4040
paragraphStyle.alignment = .center
4141

42-
let attributes: [String: Any] = [
43-
NSFontAttributeName: font,
44-
NSForegroundColorAttributeName: textColor,
45-
NSParagraphStyleAttributeName: paragraphStyle,
42+
let attributes: [NSAttributedStringKey: Any] = [
43+
NSAttributedStringKey.font: font,
44+
NSAttributedStringKey.foregroundColor: textColor,
45+
NSAttributedStringKey.paragraphStyle: paragraphStyle,
4646
]
4747

4848
guard let encoder = encoder else {
@@ -51,7 +51,7 @@ public final class CDCodabarView: UIView {
5151
let textSize = text.boundingRect(
5252
with: CGSize(width: bounds.size.width, height: CGFloat.greatestFiniteMagnitude),
5353
options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin],
54-
attributes: [NSFontAttributeName: font],
54+
attributes: [NSAttributedStringKey.font: font],
5555
context: nil
5656
)
5757

@@ -69,7 +69,7 @@ public final class CDCodabarView: UIView {
6969
let labelHeight = ceil(code.boundingRect(
7070
with: CGSize(width: bounds.size.width, height: CGFloat.greatestFiniteMagnitude),
7171
options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin],
72-
attributes: [NSFontAttributeName: font],
72+
attributes: [NSAttributedStringKey.font: font],
7373
context: nil).height)
7474
let barHeight = bounds.size.height - (hideCode ? 0 : labelHeight + padding)
7575
let sequence = encoder.sequence()

CDCodabarViewExample.xcodeproj/project.pbxproj

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,14 @@
153153
2092DBCF1E9BC1B300B735A5 = {
154154
CreatedOnToolsVersion = 8.3;
155155
DevelopmentTeam = B3YTJ78KXJ;
156+
LastSwiftMigration = 0940;
156157
ProvisioningStyle = Automatic;
157158
TestTargetID = 607FACCF1AFB9204008FA782;
158159
};
159160
607FACCF1AFB9204008FA782 = {
160161
CreatedOnToolsVersion = 6.3.1;
161162
DevelopmentTeam = JU6JS2KXPW;
162-
LastSwiftMigration = 0810;
163+
LastSwiftMigration = 0940;
163164
};
164165
};
165166
};
@@ -248,7 +249,8 @@
248249
PRODUCT_BUNDLE_IDENTIFIER = com.appunite.CDCodabarViewTests;
249250
PRODUCT_NAME = "$(TARGET_NAME)";
250251
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
251-
SWIFT_VERSION = 3.0;
252+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
253+
SWIFT_VERSION = 4.0;
252254
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarView_Example.app/CDCodabarView_Example";
253255
};
254256
name = Debug;
@@ -266,7 +268,8 @@
266268
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
267269
PRODUCT_BUNDLE_IDENTIFIER = com.appunite.CDCodabarViewTests;
268270
PRODUCT_NAME = "$(TARGET_NAME)";
269-
SWIFT_VERSION = 3.0;
271+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
272+
SWIFT_VERSION = 4.0;
270273
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarView_Example.app/CDCodabarView_Example";
271274
};
272275
name = Release;
@@ -370,7 +373,8 @@
370373
PRODUCT_BUNDLE_IDENTIFIER = com.jcdigital.CDCodabarViewExample;
371374
PRODUCT_NAME = "$(TARGET_NAME)";
372375
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
373-
SWIFT_VERSION = 3.0;
376+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
377+
SWIFT_VERSION = 4.0;
374378
};
375379
name = Debug;
376380
};
@@ -385,7 +389,8 @@
385389
MODULE_NAME = ExampleApp;
386390
PRODUCT_BUNDLE_IDENTIFIER = com.jcdigital.CDCodabarViewExample;
387391
PRODUCT_NAME = "$(TARGET_NAME)";
388-
SWIFT_VERSION = 3.0;
392+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
393+
SWIFT_VERSION = 4.0;
389394
};
390395
name = Release;
391396
};
@@ -399,6 +404,7 @@
399404
2092DBD91E9BC1B300B735A5 /* Release */,
400405
);
401406
defaultConfigurationIsVisible = 0;
407+
defaultConfigurationName = Release;
402408
};
403409
607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "CDCodabarViewExample" */ = {
404410
isa = XCConfigurationList;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

CDCodabarViewTests/EncoderSpecs.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,48 @@ import XCTest
1313
class CDCodabarViewTests: XCTestCase {
1414

1515
func testThatZeroLetterCodeIsInvalid() {
16-
let encoder = CDCodabarEncoder(code: "")
16+
let encoder = try? CDCodabarEncoder(code: "")
1717
XCTAssertNil(encoder)
1818
}
1919

2020
func testThat1LetterCodeIsInvalid() {
21-
let encoder = CDCodabarEncoder(code: "A")
21+
let encoder = try? CDCodabarEncoder(code: "A")
2222
XCTAssertNil(encoder)
2323
}
2424

2525
func testThat2LettersCodeIsInvalid() {
26-
let encoder = CDCodabarEncoder(code: "A0")
26+
let encoder = try? CDCodabarEncoder(code: "A0")
2727
XCTAssertNil(encoder)
2828
}
2929

3030
func testThat3LettersCodeIsValid() {
31-
let encoder = CDCodabarEncoder(code: "A0B")
31+
let encoder = try? CDCodabarEncoder(code: "A0B")
3232
XCTAssertNotNil(encoder)
3333
}
3434

3535
func testThat17LettersCodeIsInvalid() {
36-
let encoder = CDCodabarEncoder(code: "A000000000000000B")
36+
let encoder = try? CDCodabarEncoder(code: "A000000000000000B")
3737
XCTAssertNil(encoder)
3838
}
3939

4040
func testThatCodeWithWrongStartLetterIsInvalid() {
41-
let encoder = CDCodabarEncoder(code: "E00000000000B")
41+
let encoder = try? CDCodabarEncoder(code: "E00000000000B")
4242
XCTAssertNil(encoder)
4343
}
4444

4545
func testThatCodeWithWrongStopLetterIsInvalid() {
46-
let encoder = CDCodabarEncoder(code: "A00000000000E")
46+
let encoder = try? CDCodabarEncoder(code: "A00000000000E")
4747
XCTAssertNil(encoder)
4848
}
4949

5050
func testThreeCodeWithUnsupportedCharacterIsInvalid() {
51-
let encoder = CDCodabarEncoder(code: "A!B")
51+
let encoder = try? CDCodabarEncoder(code: "A!B")
5252
XCTAssertNil(encoder)
5353
}
5454

5555
func testExampleSequance() {
56-
let encoder = CDCodabarEncoder(code: "A012B")
56+
let encoder = try? CDCodabarEncoder(code: "A012B")
57+
XCTAssertNotNil(encoder)
5758
XCTAssertEqual(encoder!.sequence(), [
5859
1, 0, 1, 1, 0, 0, 1, 0, 0, 1,
5960
0,

0 commit comments

Comments
 (0)