Skip to content

Commit bac4a72

Browse files
committed
feat: Add Swift 4 Support
BREAKING CHANGE: Swift 3 Support is removed
1 parent 3d0c638 commit bac4a72

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
matrix:
22
include:
3-
- os: osx
4-
osx_image: xcode8.3
5-
env: SWIFT_VERSION=3.1.1
63
- os: osx
74
osx_image: xcode9
85
env: SWIFT_VERSION=4.0

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
### Breaking Changes
66

7+
- Support for Swift 3 was removed.
78
- `ValidationResult.Valid` was renamed to `ValidationResult.valid`.
89

910
### Enhancements
1011

12+
- Support for Swift 4 has been added.
1113
- `uri` format is now validated.
1214

1315

JSONSchema.xcodeproj/project.pbxproj

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@
310310
TargetAttributes = {
311311
27CF7EE81A9B9EDA0063FDE4 = {
312312
CreatedOnToolsVersion = 6.1.1;
313-
LastSwiftMigration = 0800;
313+
LastSwiftMigration = 0910;
314314
};
315315
27CF7EF31A9B9EDA0063FDE4 = {
316316
CreatedOnToolsVersion = 6.1.1;
317-
LastSwiftMigration = 0800;
317+
LastSwiftMigration = 0910;
318318
};
319319
};
320320
};
@@ -463,6 +463,7 @@
463463
ONLY_ACTIVE_ARCH = YES;
464464
SDKROOT = macosx;
465465
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
466+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
466467
VERSIONING_SYSTEM = "apple-generic";
467468
VERSION_INFO_PREFIX = "";
468469
};
@@ -510,6 +511,7 @@
510511
MTL_ENABLE_DEBUG_INFO = NO;
511512
SDKROOT = macosx;
512513
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
514+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
513515
VERSIONING_SYSTEM = "apple-generic";
514516
VERSION_INFO_PREFIX = "";
515517
};
@@ -532,7 +534,8 @@
532534
PRODUCT_NAME = "$(TARGET_NAME)";
533535
SKIP_INSTALL = YES;
534536
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
535-
SWIFT_VERSION = 3.0;
537+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
538+
SWIFT_VERSION = 4.0;
536539
};
537540
name = Debug;
538541
};
@@ -552,7 +555,8 @@
552555
PRODUCT_BUNDLE_IDENTIFIER = "org.cocode.$(PRODUCT_NAME:rfc1034identifier)";
553556
PRODUCT_NAME = "$(TARGET_NAME)";
554557
SKIP_INSTALL = YES;
555-
SWIFT_VERSION = 3.0;
558+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
559+
SWIFT_VERSION = 4.0;
556560
};
557561
name = Release;
558562
};
@@ -568,7 +572,8 @@
568572
INFOPLIST_FILE = Tests/Info.plist;
569573
PRODUCT_BUNDLE_IDENTIFIER = "org.cocode.$(PRODUCT_NAME:rfc1034identifier)";
570574
PRODUCT_NAME = "$(TARGET_NAME)";
571-
SWIFT_VERSION = 3.0;
575+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
576+
SWIFT_VERSION = 4.0;
572577
};
573578
name = Debug;
574579
};
@@ -580,7 +585,8 @@
580585
INFOPLIST_FILE = Tests/Info.plist;
581586
PRODUCT_BUNDLE_IDENTIFIER = "org.cocode.$(PRODUCT_NAME:rfc1034identifier)";
582587
PRODUCT_NAME = "$(TARGET_NAME)";
583-
SWIFT_VERSION = 3.0;
588+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
589+
SWIFT_VERSION = 4.0;
584590
};
585591
name = Release;
586592
};

Sources/JSONSchema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public enum Type: Swift.String {
2121
extension String {
2222
func stringByRemovingPrefix(_ prefix:String) -> String? {
2323
if hasPrefix(prefix) {
24-
let index = characters.index(startIndex, offsetBy: prefix.characters.count)
24+
let index = self.index(startIndex, offsetBy: prefix.count)
2525
return substring(from: index)
2626
}
2727

Sources/Validators.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func validateEnum(_ values: [Any]) -> (_ value: Any) -> ValidationResult {
193193
func validateLength(_ comparitor: @escaping ((Int, Int) -> (Bool)), length: Int, error: String) -> (_ value: Any) -> ValidationResult {
194194
return { value in
195195
if let value = value as? String {
196-
if !comparitor(value.characters.count, length) {
196+
if !comparitor(value.count, length) {
197197
return .invalid([error])
198198
}
199199
}
@@ -207,7 +207,7 @@ func validatePattern(_ pattern: String) -> (_ value: Any) -> ValidationResult {
207207
if let value = value as? String {
208208
let expression = try? NSRegularExpression(pattern: pattern, options: NSRegularExpression.Options(rawValue: 0))
209209
if let expression = expression {
210-
let range = NSMakeRange(0, value.characters.count)
210+
let range = NSMakeRange(0, value.count)
211211
if expression.matches(in: value, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: range).count == 0 {
212212
return .invalid(["'\(value)' does not match pattern: '\(pattern)'"])
213213
}
@@ -344,7 +344,7 @@ func validateProperties(_ properties: [String:Validator]?, patternProperties: [S
344344
do {
345345
let expression = try NSRegularExpression(pattern: pattern, options: NSRegularExpression.Options(rawValue: 0))
346346
let keys = value.keys.filter {
347-
(key: String) in expression.matches(in: key, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, key.characters.count)).count > 0
347+
(key: String) in expression.matches(in: key, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, key.count)).count > 0
348348
}
349349

350350
allKeys.addObjects(from: Array(keys))
@@ -400,7 +400,7 @@ func validateDependencies(_ key: String, dependencies: [String]) -> (_ value: An
400400
func validateIPv4(_ value:Any) -> ValidationResult {
401401
if let ipv4 = value as? String {
402402
if let expression = try? NSRegularExpression(pattern: "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", options: NSRegularExpression.Options(rawValue: 0)) {
403-
if expression.matches(in: ipv4, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, ipv4.characters.count)).count == 1 {
403+
if expression.matches(in: ipv4, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, ipv4.count)).count == 1 {
404404
return .valid
405405
}
406406
}
@@ -429,10 +429,10 @@ func validateURI(_ value:Any) -> ValidationResult {
429429
// Using the regex from http://blog.dieweltistgarnichtso.net/constructing-a-regular-expression-that-matches-uris
430430

431431
if let expression = try? NSRegularExpression(pattern: "((?<=\\()[A-Za-z][A-Za-z0-9\\+\\.\\-]*:([A-Za-z0-9\\.\\-_~:/\\?#\\[\\]@!\\$&'\\(\\)\\*\\+,;=]|%[A-Fa-f0-9]{2})+(?=\\)))|([A-Za-z][A-Za-z0-9\\+\\.\\-]*:([A-Za-z0-9\\.\\-_~:/\\?#\\[\\]@!\\$&'\\(\\)\\*\\+,;=]|%[A-Fa-f0-9]{2})+)", options: NSRegularExpression.Options(rawValue: 0)) {
432-
let result = expression.matches(in: uri, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, uri.characters.count))
432+
let result = expression.matches(in: uri, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, uri.count))
433433
if result.count == 1 {
434434
let foundRange = result[0].range
435-
if foundRange.location == 0 && foundRange.length == uri.characters.count {
435+
if foundRange.location == 0 && foundRange.length == uri.count {
436436
return .valid
437437
}
438438
}

Tests/JSONSchemaCases.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import XCTest
1111
import JSONSchema
1212

1313
func fixture(_ named:String, forObject:Any) -> Data {
14-
let bundle = Bundle(for:object_getClass(forObject))
14+
let bundle = Bundle(for:object_getClass(forObject)!)
1515
let path = bundle.url(forResource: named, withExtension: nil)!
1616
let data = try! Data(contentsOf: path)
1717
return data

0 commit comments

Comments
 (0)