From 80dd5580d93f37a47555bba483713a4d09e3199e Mon Sep 17 00:00:00 2001 From: Ben Scheirman Date: Thu, 12 Oct 2017 21:50:50 -0500 Subject: [PATCH 01/19] Fix build errors with Xcode 9 --- Freddy.xcodeproj/project.pbxproj | 14 +++++++++++++- .../xcshareddata/xcschemes/Freddy.xcscheme | 4 +++- .../xcshareddata/xcschemes/MobileFreddy.xcscheme | 4 +++- .../xcshareddata/xcschemes/NanoFreddy.xcscheme | 4 +++- .../xcshareddata/xcschemes/TVFreddy.xcscheme | 4 +++- Sources/JSONDecodable.swift | 6 +++--- Sources/JSONParser.swift | 9 +++++---- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Freddy.xcodeproj/project.pbxproj b/Freddy.xcodeproj/project.pbxproj index 8c0cfce..2060660 100644 --- a/Freddy.xcodeproj/project.pbxproj +++ b/Freddy.xcodeproj/project.pbxproj @@ -474,7 +474,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Big Nerd Ranch"; TargetAttributes = { DB6ADF1E1C23610B00D77BF1 = { @@ -734,6 +734,12 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF801C23617500D77BF1 /* Debug.xcconfig */; buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; ENABLE_TESTABILITY = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -744,6 +750,12 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF821C23617500D77BF1 /* Release.xcconfig */; buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; SDKROOT = iphoneos; }; name = Release; diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme index 7cbb854..052f726 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme @@ -1,6 +1,6 @@ @@ -70,6 +71,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme index f90613e..994c625 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme @@ -1,6 +1,6 @@ @@ -70,6 +71,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme index e4c6b34..7c6d479 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme index 3c83c3f..1e72f51 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme @@ -1,6 +1,6 @@ @@ -70,6 +71,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Sources/JSONDecodable.swift b/Sources/JSONDecodable.swift index ea4c036..89c7f14 100644 --- a/Sources/JSONDecodable.swift +++ b/Sources/JSONDecodable.swift @@ -134,7 +134,7 @@ internal extension JSON { static func getArray(from json: JSON) throws -> [JSON] { // Ideally should be expressed as a conditional protocol implementation on Swift.Array. guard case let .array(array) = json else { - throw Error.valueNotConvertible(value: json, to: Swift.Array) + throw Error.valueNotConvertible(value: json, to: Swift.Array.self) } return array } @@ -147,7 +147,7 @@ internal extension JSON { static func getDictionary(from json: JSON) throws -> [String: JSON] { // Ideally should be expressed as a conditional protocol implementation on Swift.Dictionary. guard case let .dictionary(dictionary) = json else { - throw Error.valueNotConvertible(value: json, to: Swift.Dictionary) + throw Error.valueNotConvertible(value: json, to: Swift.Dictionary.self) } return dictionary } @@ -174,7 +174,7 @@ internal extension JSON { /// - seealso: `JSON.decode(_:type:)` static func decodedDictionary(from json: JSON) throws -> [Swift.String: Decoded] { guard case let .dictionary(dictionary) = json else { - throw Error.valueNotConvertible(value: json, to: Swift.Dictionary) + throw Error.valueNotConvertible(value: json, to: Swift.Dictionary.self) } var decodedDictionary = Swift.Dictionary(minimumCapacity: dictionary.count) for (key, value) in dictionary { diff --git a/Sources/JSONParser.swift b/Sources/JSONParser.swift index ed3f475..cb2b372 100644 --- a/Sources/JSONParser.swift +++ b/Sources/JSONParser.swift @@ -455,12 +455,13 @@ public struct JSONParser { parser.parseLeadingZero() case .preDecimalDigits: - try parser.parsePreDecimalDigits { c in - guard case let (exponent, .none) = 10.multipliedReportingOverflow(by: value) else { + var mutableParser = parser + try mutableParser.parsePreDecimalDigits { c in + guard case let (exponent, false) = 10.multipliedReportingOverflow(by: value) else { throw InternalError.numberOverflow(offset: parser.start) } - guard case let (newValue, .none) = exponent.addingReportingOverflow(Int(c - Literal.zero)) else { + guard case let (newValue, false) = exponent.addingReportingOverflow(Int(c - Literal.zero)) else { throw InternalError.numberOverflow(offset: parser.start) } @@ -480,7 +481,7 @@ public struct JSONParser { } } - guard case let (signedValue, .none) = sign.rawValue.multipliedReportingOverflow(by: value) else { + guard case let (signedValue, false) = sign.rawValue.multipliedReportingOverflow(by: value) else { throw InternalError.numberOverflow(offset: parser.start) } From 207f4a680ed20cdfb3bb375ec480f89ad049b2ed Mon Sep 17 00:00:00 2001 From: Ben Scheirman Date: Sun, 15 Oct 2017 17:17:04 -0500 Subject: [PATCH 02/19] Capture reference for use in throws to comply with Swift 4 --- Sources/JSONParser.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/JSONParser.swift b/Sources/JSONParser.swift index cb2b372..55ddae7 100644 --- a/Sources/JSONParser.swift +++ b/Sources/JSONParser.swift @@ -455,14 +455,14 @@ public struct JSONParser { parser.parseLeadingZero() case .preDecimalDigits: - var mutableParser = parser - try mutableParser.parsePreDecimalDigits { c in + let start = parser.start + try parser.parsePreDecimalDigits { c in guard case let (exponent, false) = 10.multipliedReportingOverflow(by: value) else { - throw InternalError.numberOverflow(offset: parser.start) + throw InternalError.numberOverflow(offset: start) } guard case let (newValue, false) = exponent.addingReportingOverflow(Int(c - Literal.zero)) else { - throw InternalError.numberOverflow(offset: parser.start) + throw InternalError.numberOverflow(offset: start) } value = newValue From b08a03b3cbf4089afaf585bee871c0039a2a5584 Mon Sep 17 00:00:00 2001 From: David House Date: Sun, 15 Oct 2017 09:04:48 -0400 Subject: [PATCH 03/19] Disable code coverage for release builds fixes #262 --- Freddy.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Freddy.xcodeproj/project.pbxproj b/Freddy.xcodeproj/project.pbxproj index 2060660..ef92d06 100644 --- a/Freddy.xcodeproj/project.pbxproj +++ b/Freddy.xcodeproj/project.pbxproj @@ -773,6 +773,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { + CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -809,6 +810,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { + CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = macosx; SWIFT_VERSION = 3.0; }; @@ -847,6 +849,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { + CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; }; @@ -883,6 +886,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { + CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = watchos; TARGETED_DEVICE_FAMILY = 4; }; From e0f93dfde721160118774f8578cd6e74640d82a0 Mon Sep 17 00:00:00 2001 From: David House Date: Wed, 18 Oct 2017 11:42:02 -0400 Subject: [PATCH 04/19] Update Freddy podspec for 3.0.3 version --- Freddy.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Freddy.podspec b/Freddy.podspec index 6d6f9dd..9a96351 100644 --- a/Freddy.podspec +++ b/Freddy.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Freddy" - s.version = "3.0.2" + s.version = "3.0.3" s.summary = "A JSON parsing library written in Swift" s.description = <<-DESC @@ -28,5 +28,5 @@ Pod::Spec.new do |s| s.source_files = "Sources/**/*.{h,swift}" s.requires_arc = true - s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' } + s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.2' } end From 1752aa232e86be9cf619ac69e46380eb1dbdfeb4 Mon Sep 17 00:00:00 2001 From: Mark Lilback Date: Tue, 21 Nov 2017 19:11:51 -0500 Subject: [PATCH 05/19] switched to use casts instead of CFNumberGetType for decoding numbers via JSONSerialization --- Sources/JSONParsing.swift | 40 ++++++++------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/Sources/JSONParsing.swift b/Sources/JSONParsing.swift index 0a03021..98b8b6a 100644 --- a/Sources/JSONParsing.swift +++ b/Sources/JSONParsing.swift @@ -56,38 +56,14 @@ extension JSONSerialization: JSONParserType { /// - returns: An instance of `JSON` matching the JSON given to the function. public static func makeJSON(with object: Any) -> JSON { switch object { - case let n as NSNumber: - let numberType = CFNumberGetType(n) - switch numberType { - case .charType: - return .bool(n.boolValue) - - case .shortType, .intType, .longType, .cfIndexType, .nsIntegerType, .sInt8Type, .sInt16Type, .sInt32Type: - return .int(n.intValue) - - case .sInt64Type, .longLongType /* overflows 32-bit Int */: - #if /* 32-bit arch */ arch(arm) || arch(i386) - // Why double, when the Freddy parser would bump to String? - // - // Returning Double avoids making the type depend on whether you're running - // 32-bit or 64-bit code when using the NSJSONSerialization parser. - // NSJSONSerialization appears to bump numbers larger than Int.max to Double on - // 64-bit platforms but use .SInt64Type on 32-bit platforms. - // If we returned a String here, you'd get a String value on 32-bit, - // but a Double value on 64-bit. Instead, we return Double. - // - // This means that, if you switch parsers, - // you'll have to switch from .double to .string for pulling out - // overflowing values, but if you stick with a single parser, - // you at least won't have architecture-dependent lookups! - return .double(n.doubleValue) - #else - return .int(n.intValue) - #endif - - case .float32Type, .float64Type, .floatType, .doubleType, .cgFloatType: - return .double(n.doubleValue) - } + case let n as Int: + return .int(n) + + case let n as Double: + return .double(n) + + case let n as Bool: + return .bool(n) case let arr as [Any]: return makeJSONArray(arr) From 43153d9fa42075646f232f69072b49ffeb9916e6 Mon Sep 17 00:00:00 2001 From: Mark Dalrymple Date: Sat, 24 Feb 2018 09:59:19 -0500 Subject: [PATCH 06/19] Mechanical update to swift 4 --- Freddy.xcodeproj/project.pbxproj | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Freddy.xcodeproj/project.pbxproj b/Freddy.xcodeproj/project.pbxproj index ef92d06..dd0eaff 100644 --- a/Freddy.xcodeproj/project.pbxproj +++ b/Freddy.xcodeproj/project.pbxproj @@ -487,11 +487,11 @@ }; DB6ADF3D1C23612000D77BF1 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0920; }; DB6ADF461C23612000D77BF1 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0920; }; DB6ADF591C23612900D77BF1 = { CreatedOnToolsVersion = 7.2; @@ -802,7 +802,8 @@ baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { SDKROOT = macosx; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -812,7 +813,8 @@ buildSettings = { CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = macosx; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -822,7 +824,8 @@ buildSettings = { INFOPLIST_FILE = Tests/FreddyTests/Info.plist; SDKROOT = macosx; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -832,7 +835,8 @@ buildSettings = { INFOPLIST_FILE = Tests/FreddyTests/Info.plist; SDKROOT = macosx; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; From 8befede92c35ad5a3ba7821f96a73a9f0c0d2aa4 Mon Sep 17 00:00:00 2001 From: Mark Dalrymple Date: Sat, 24 Feb 2018 10:00:26 -0500 Subject: [PATCH 07/19] Fixes errors --- Tests/FreddyTests/JSONDecodableTests.swift | 4 ++-- Tests/FreddyTests/JSONSubscriptingTests.swift | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/FreddyTests/JSONDecodableTests.swift b/Tests/FreddyTests/JSONDecodableTests.swift index 13debcf..f81c592 100644 --- a/Tests/FreddyTests/JSONDecodableTests.swift +++ b/Tests/FreddyTests/JSONDecodableTests.swift @@ -228,7 +228,7 @@ class JSONDecodableTests: XCTestCase { let oneTwoThreeJSON: JSON = [1,2,3] do { - let decodedOneTwoThree = try oneTwoThreeJSON.decodedArray(type: Swift.Int) + let decodedOneTwoThree = try oneTwoThreeJSON.decodedArray(type: Swift.Int.self) XCTAssertEqual(decodedOneTwoThree, [1,2,3], "`decodedOneTwoThree` should be equal to `[1,2,3]`.") } catch { XCTFail("`decodedOneTwoThree` should be equal to `[1,2,3]`.") @@ -239,7 +239,7 @@ class JSONDecodableTests: XCTestCase { let oneTwoThreeJSON: JSON = ["one": 1, "two": 2, "three": 3] do { - let decodedOneTwoThree = try oneTwoThreeJSON.decodedDictionary(type: Swift.Int) + let decodedOneTwoThree = try oneTwoThreeJSON.decodedDictionary(type: Swift.Int.self) XCTAssertEqual(decodedOneTwoThree, ["one": 1, "two": 2, "three": 3], "`decodedOneTwoThree` should be equal to `[\"one\": 1, \"two\": 2, \"three\": 3]`.") } catch { XCTFail("`decodedOneTwoThree` should be equal to `[\"one\": 1, \"two\": 2, \"three\": 3]`.") diff --git a/Tests/FreddyTests/JSONSubscriptingTests.swift b/Tests/FreddyTests/JSONSubscriptingTests.swift index f34142c..d1ed344 100644 --- a/Tests/FreddyTests/JSONSubscriptingTests.swift +++ b/Tests/FreddyTests/JSONSubscriptingTests.swift @@ -306,7 +306,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try residentJSON.decode(at: "residents", 1, "name", "initial", type: Resident.self) } catch JSON.Error.unexpectedSubscript(let type) { - XCTAssert(type == Swift.String, "The dictionary at index 1 should not be subscriptable by: \(type).") + XCTAssert(type == Swift.String.self, "The dictionary at index 1 should not be subscriptable by: \(type).") } catch { XCTFail("This should not be: \(error).") } @@ -392,7 +392,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try json.getInt(at: "people", 0, "name") } catch let JSON.Error.valueNotConvertible(value, to) { - XCTAssert(to == Swift.Int, "The error should be due the value not being an `Int` case, but was \(to).") + XCTAssert(to == Swift.Int.self, "The error should be due the value not being an `Int` case, but was \(to).") XCTAssert(value == "Matt Mathias", "The error should be due the value being the String 'Matt Mathias', but was \(value).") } catch { XCTFail("The error should be due to `name` not being convertible to `int`, but was: \(error).") @@ -403,7 +403,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try json.getString(at: "people", "name") } catch JSON.Error.unexpectedSubscript(let type) { - XCTAssert(type == Swift.String, "The error should be due the value not being subscriptable with string `String` case, but was \(type).") + XCTAssert(type == Swift.String.self, "The error should be due the value not being subscriptable with string `String` case, but was \(type).") } catch { XCTFail("The error should be due to the `people` `Array` not being subscriptable with `String`s, but was: \(error).") } From 252e71978a8dd492ccb98b02919dc56d05eae5af Mon Sep 17 00:00:00 2001 From: Mark Dalrymple Date: Sat, 24 Feb 2018 10:01:41 -0500 Subject: [PATCH 08/19] Fixits warnings --- Sources/JSONDecodable.swift | 4 ++-- Tests/FreddyTests/JSONParserTests.swift | 2 +- Tests/FreddyTests/JSONSerializingTests.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/JSONDecodable.swift b/Sources/JSONDecodable.swift index 89c7f14..8e47fa5 100644 --- a/Sources/JSONDecodable.swift +++ b/Sources/JSONDecodable.swift @@ -57,8 +57,8 @@ extension Int: JSONDecodable { self = int } else if case let .string(string) = json, let double = Double(string), - let decimalSeparator = string.characters.index(of: "."), - let int = Int(String(string.characters.prefix(upTo: decimalSeparator))), + let decimalSeparator = string.index(of: "."), + let int = Int(String(string.prefix(upTo: decimalSeparator))), double == Double(int) { self = int } else { diff --git a/Tests/FreddyTests/JSONParserTests.swift b/Tests/FreddyTests/JSONParserTests.swift index 5223beb..995ff44 100644 --- a/Tests/FreddyTests/JSONParserTests.swift +++ b/Tests/FreddyTests/JSONParserTests.swift @@ -200,7 +200,7 @@ class JSONParserTests: XCTestCase { ] { do { let value = try JSONParser.parse(string).getDouble() - XCTAssertEqualWithAccuracy(value, shouldBeDouble, accuracy: DBL_EPSILON) + XCTAssertEqual(value, shouldBeDouble, accuracy: .ulpOfOne) } catch { XCTFail("Unexpected error: \(error)") } diff --git a/Tests/FreddyTests/JSONSerializingTests.swift b/Tests/FreddyTests/JSONSerializingTests.swift index 2136d0d..c6d2a7e 100644 --- a/Tests/FreddyTests/JSONSerializingTests.swift +++ b/Tests/FreddyTests/JSONSerializingTests.swift @@ -14,7 +14,7 @@ class JSONSerializingTests: XCTestCase { func testThatJSONCanBeSerializedToString() { let string = try! json.serializeString() - XCTAssertGreaterThan(string.characters.count, 0, "There should be characters.") + XCTAssertGreaterThan(string.count, 0, "There should be characters.") } func testThatJSONDataIsEqual() { From 9ee5f83fb7bfe8a236411c0259799ecee3a70984 Mon Sep 17 00:00:00 2001 From: Mark Dalrymple Date: Sat, 24 Feb 2018 10:03:36 -0500 Subject: [PATCH 09/19] Turns off @objc swift 3 inference (event though I supposedly turned that off during the migration... --- Freddy.xcodeproj/project.pbxproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Freddy.xcodeproj/project.pbxproj b/Freddy.xcodeproj/project.pbxproj index dd0eaff..dd1aab4 100644 --- a/Freddy.xcodeproj/project.pbxproj +++ b/Freddy.xcodeproj/project.pbxproj @@ -743,6 +743,7 @@ ENABLE_TESTABILITY = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; }; name = Debug; }; @@ -757,6 +758,7 @@ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; SDKROOT = iphoneos; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; }; name = Release; }; @@ -802,7 +804,6 @@ baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; }; name = Debug; @@ -813,7 +814,6 @@ buildSettings = { CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; }; name = Release; @@ -824,7 +824,6 @@ buildSettings = { INFOPLIST_FILE = Tests/FreddyTests/Info.plist; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; }; name = Debug; @@ -835,7 +834,6 @@ buildSettings = { INFOPLIST_FILE = Tests/FreddyTests/Info.plist; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 4.0; }; name = Release; From d1f2a66fd3ee156e854ea0d4db064adb7fca489f Mon Sep 17 00:00:00 2001 From: Mark Dalrymple Date: Sat, 24 Feb 2018 10:27:10 -0500 Subject: [PATCH 10/19] Revert "Merge pull request #276 from markd2/markd/swift-4" This reverts commit 434bd3b72650d1c26e7f784a02bd7b3b2fad31e2, reversing changes made to daacb3c41e384bffff6e22b2f1f241d4e7ff3132. --- Freddy.xcodeproj/project.pbxproj | 14 ++++++-------- Sources/JSONDecodable.swift | 4 ++-- Tests/FreddyTests/JSONDecodableTests.swift | 4 ++-- Tests/FreddyTests/JSONParserTests.swift | 2 +- Tests/FreddyTests/JSONSerializingTests.swift | 2 +- Tests/FreddyTests/JSONSubscriptingTests.swift | 6 +++--- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Freddy.xcodeproj/project.pbxproj b/Freddy.xcodeproj/project.pbxproj index dd1aab4..ef92d06 100644 --- a/Freddy.xcodeproj/project.pbxproj +++ b/Freddy.xcodeproj/project.pbxproj @@ -487,11 +487,11 @@ }; DB6ADF3D1C23612000D77BF1 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0920; + LastSwiftMigration = 0800; }; DB6ADF461C23612000D77BF1 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0920; + LastSwiftMigration = 0800; }; DB6ADF591C23612900D77BF1 = { CreatedOnToolsVersion = 7.2; @@ -743,7 +743,6 @@ ENABLE_TESTABILITY = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; }; name = Debug; }; @@ -758,7 +757,6 @@ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; SDKROOT = iphoneos; - SWIFT_SWIFT3_OBJC_INFERENCE = Off; }; name = Release; }; @@ -804,7 +802,7 @@ baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { SDKROOT = macosx; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -814,7 +812,7 @@ buildSettings = { CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = macosx; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -824,7 +822,7 @@ buildSettings = { INFOPLIST_FILE = Tests/FreddyTests/Info.plist; SDKROOT = macosx; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -834,7 +832,7 @@ buildSettings = { INFOPLIST_FILE = Tests/FreddyTests/Info.plist; SDKROOT = macosx; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Sources/JSONDecodable.swift b/Sources/JSONDecodable.swift index 8e47fa5..89c7f14 100644 --- a/Sources/JSONDecodable.swift +++ b/Sources/JSONDecodable.swift @@ -57,8 +57,8 @@ extension Int: JSONDecodable { self = int } else if case let .string(string) = json, let double = Double(string), - let decimalSeparator = string.index(of: "."), - let int = Int(String(string.prefix(upTo: decimalSeparator))), + let decimalSeparator = string.characters.index(of: "."), + let int = Int(String(string.characters.prefix(upTo: decimalSeparator))), double == Double(int) { self = int } else { diff --git a/Tests/FreddyTests/JSONDecodableTests.swift b/Tests/FreddyTests/JSONDecodableTests.swift index f81c592..13debcf 100644 --- a/Tests/FreddyTests/JSONDecodableTests.swift +++ b/Tests/FreddyTests/JSONDecodableTests.swift @@ -228,7 +228,7 @@ class JSONDecodableTests: XCTestCase { let oneTwoThreeJSON: JSON = [1,2,3] do { - let decodedOneTwoThree = try oneTwoThreeJSON.decodedArray(type: Swift.Int.self) + let decodedOneTwoThree = try oneTwoThreeJSON.decodedArray(type: Swift.Int) XCTAssertEqual(decodedOneTwoThree, [1,2,3], "`decodedOneTwoThree` should be equal to `[1,2,3]`.") } catch { XCTFail("`decodedOneTwoThree` should be equal to `[1,2,3]`.") @@ -239,7 +239,7 @@ class JSONDecodableTests: XCTestCase { let oneTwoThreeJSON: JSON = ["one": 1, "two": 2, "three": 3] do { - let decodedOneTwoThree = try oneTwoThreeJSON.decodedDictionary(type: Swift.Int.self) + let decodedOneTwoThree = try oneTwoThreeJSON.decodedDictionary(type: Swift.Int) XCTAssertEqual(decodedOneTwoThree, ["one": 1, "two": 2, "three": 3], "`decodedOneTwoThree` should be equal to `[\"one\": 1, \"two\": 2, \"three\": 3]`.") } catch { XCTFail("`decodedOneTwoThree` should be equal to `[\"one\": 1, \"two\": 2, \"three\": 3]`.") diff --git a/Tests/FreddyTests/JSONParserTests.swift b/Tests/FreddyTests/JSONParserTests.swift index 995ff44..5223beb 100644 --- a/Tests/FreddyTests/JSONParserTests.swift +++ b/Tests/FreddyTests/JSONParserTests.swift @@ -200,7 +200,7 @@ class JSONParserTests: XCTestCase { ] { do { let value = try JSONParser.parse(string).getDouble() - XCTAssertEqual(value, shouldBeDouble, accuracy: .ulpOfOne) + XCTAssertEqualWithAccuracy(value, shouldBeDouble, accuracy: DBL_EPSILON) } catch { XCTFail("Unexpected error: \(error)") } diff --git a/Tests/FreddyTests/JSONSerializingTests.swift b/Tests/FreddyTests/JSONSerializingTests.swift index c6d2a7e..2136d0d 100644 --- a/Tests/FreddyTests/JSONSerializingTests.swift +++ b/Tests/FreddyTests/JSONSerializingTests.swift @@ -14,7 +14,7 @@ class JSONSerializingTests: XCTestCase { func testThatJSONCanBeSerializedToString() { let string = try! json.serializeString() - XCTAssertGreaterThan(string.count, 0, "There should be characters.") + XCTAssertGreaterThan(string.characters.count, 0, "There should be characters.") } func testThatJSONDataIsEqual() { diff --git a/Tests/FreddyTests/JSONSubscriptingTests.swift b/Tests/FreddyTests/JSONSubscriptingTests.swift index d1ed344..f34142c 100644 --- a/Tests/FreddyTests/JSONSubscriptingTests.swift +++ b/Tests/FreddyTests/JSONSubscriptingTests.swift @@ -306,7 +306,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try residentJSON.decode(at: "residents", 1, "name", "initial", type: Resident.self) } catch JSON.Error.unexpectedSubscript(let type) { - XCTAssert(type == Swift.String.self, "The dictionary at index 1 should not be subscriptable by: \(type).") + XCTAssert(type == Swift.String, "The dictionary at index 1 should not be subscriptable by: \(type).") } catch { XCTFail("This should not be: \(error).") } @@ -392,7 +392,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try json.getInt(at: "people", 0, "name") } catch let JSON.Error.valueNotConvertible(value, to) { - XCTAssert(to == Swift.Int.self, "The error should be due the value not being an `Int` case, but was \(to).") + XCTAssert(to == Swift.Int, "The error should be due the value not being an `Int` case, but was \(to).") XCTAssert(value == "Matt Mathias", "The error should be due the value being the String 'Matt Mathias', but was \(value).") } catch { XCTFail("The error should be due to `name` not being convertible to `int`, but was: \(error).") @@ -403,7 +403,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try json.getString(at: "people", "name") } catch JSON.Error.unexpectedSubscript(let type) { - XCTAssert(type == Swift.String.self, "The error should be due the value not being subscriptable with string `String` case, but was \(type).") + XCTAssert(type == Swift.String, "The error should be due the value not being subscriptable with string `String` case, but was \(type).") } catch { XCTFail("The error should be due to the `people` `Array` not being subscriptable with `String`s, but was: \(error).") } From 6010d087fc0c22fd55e9fc95a033677f5917ca85 Mon Sep 17 00:00:00 2001 From: Mark Lilback Date: Fri, 1 Jun 2018 04:36:36 -0400 Subject: [PATCH 11/19] added explicit variable type to prevent compile error on linux --- Sources/JSONParser.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/JSONParser.swift b/Sources/JSONParser.swift index 55ddae7..6e5ce61 100644 --- a/Sources/JSONParser.swift +++ b/Sources/JSONParser.swift @@ -592,7 +592,7 @@ public struct JSONParser { } private func detectingFloatingPointErrors(start loc: Int, _ f: () throws -> T) throws -> T { - let flags = FE_UNDERFLOW | FE_OVERFLOW + let flags: Int32 = FE_UNDERFLOW | FE_OVERFLOW feclearexcept(flags) let value = try f() guard fetestexcept(flags) == 0 else { From c91c17cd5ed62143eb7321acd540c595264a4bd4 Mon Sep 17 00:00:00 2001 From: Mark Lilback Date: Fri, 1 Jun 2018 04:42:21 -0400 Subject: [PATCH 12/19] fixed spacing to conform to project standards --- Sources/JSONParsing.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/JSONParsing.swift b/Sources/JSONParsing.swift index 98b8b6a..6623371 100644 --- a/Sources/JSONParsing.swift +++ b/Sources/JSONParsing.swift @@ -56,14 +56,14 @@ extension JSONSerialization: JSONParserType { /// - returns: An instance of `JSON` matching the JSON given to the function. public static func makeJSON(with object: Any) -> JSON { switch object { - case let n as Int: - return .int(n) - - case let n as Double: - return .double(n) - - case let n as Bool: - return .bool(n) + case let n as Int: + return .int(n) + + case let n as Double: + return .double(n) + + case let n as Bool: + return .bool(n) case let arr as [Any]: return makeJSONArray(arr) From f895ea0448bf3341f41663e901d7ada1d9498e0e Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Fri, 1 Jun 2018 19:08:35 -0400 Subject: [PATCH 13/19] Update configurations to make Xcode happy --- Configurations/Base.xcconfig | 8 +++++++ Configurations/Debug.xcconfig | 2 +- Configurations/Release.xcconfig | 4 ++-- Freddy.xcodeproj/project.pbxproj | 24 +++---------------- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ .../xcshareddata/xcschemes/Freddy.xcscheme | 8 +++---- .../xcschemes/MobileFreddy.xcscheme | 8 +++---- .../xcschemes/NanoFreddy.xcscheme | 4 +--- .../xcshareddata/xcschemes/TVFreddy.xcscheme | 8 +++---- 9 files changed, 32 insertions(+), 42 deletions(-) create mode 100644 Freddy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Configurations/Base.xcconfig b/Configurations/Base.xcconfig index b296c23..1031e85 100644 --- a/Configurations/Base.xcconfig +++ b/Configurations/Base.xcconfig @@ -28,6 +28,14 @@ GCC_WARN_UNDECLARED_SELECTOR = YES CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR CLANG_WARN_INFINITE_RECURSION = YES CLANG_WARN_SUSPICIOUS_MOVE = YES +CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES +CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +CLANG_WARN_RANGE_LOOP_ANALYSIS = YES +CLANG_WARN_OBJC_LITERAL_CONVERSION = YES +CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES CURRENT_PROJECT_VERSION = 3.0.0 VERSION_INFO_PREFIX = diff --git a/Configurations/Debug.xcconfig b/Configurations/Debug.xcconfig index 5ae57de..bfa584d 100644 --- a/Configurations/Debug.xcconfig +++ b/Configurations/Debug.xcconfig @@ -6,5 +6,5 @@ ENABLE_TESTABILITY = YES VALIDATE_PRODUCT = NO GCC_OPTIMIZATION_LEVEL = 0 ENABLE_NS_ASSERTIONS = YES -GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 SWIFT_OPTIMIZATION_LEVEL = -Onone +SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG diff --git a/Configurations/Release.xcconfig b/Configurations/Release.xcconfig index 7e611a9..54c0af1 100644 --- a/Configurations/Release.xcconfig +++ b/Configurations/Release.xcconfig @@ -6,6 +6,6 @@ ENABLE_TESTABILITY = NO VALIDATE_PRODUCT = YES GCC_OPTIMIZATION_LEVEL = s ENABLE_NS_ASSERTIONS = NO -GCC_PREPROCESSOR_DEFINITIONS = -SWIFT_OPTIMIZATION_LEVEL = -Owholemodule +SWIFT_OPTIMIZATION_LEVEL = -O +SWIFT_COMPILATION_MODE = wholemodule COPY_PHASE_STRIP = YES diff --git a/Freddy.xcodeproj/project.pbxproj b/Freddy.xcodeproj/project.pbxproj index ef92d06..d0639df 100644 --- a/Freddy.xcodeproj/project.pbxproj +++ b/Freddy.xcodeproj/project.pbxproj @@ -474,7 +474,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0940; ORGANIZATIONNAME = "Big Nerd Ranch"; TargetAttributes = { DB6ADF1E1C23610B00D77BF1 = { @@ -487,11 +487,11 @@ }; DB6ADF3D1C23612000D77BF1 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0940; }; DB6ADF461C23612000D77BF1 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0940; }; DB6ADF591C23612900D77BF1 = { CreatedOnToolsVersion = 7.2; @@ -734,15 +734,6 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF801C23617500D77BF1 /* Debug.xcconfig */; buildSettings = { - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - ENABLE_TESTABILITY = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; }; name = Debug; }; @@ -750,13 +741,6 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB6ADF821C23617500D77BF1 /* Release.xcconfig */; buildSettings = { - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - SDKROOT = iphoneos; }; name = Release; }; @@ -802,7 +786,6 @@ baseConfigurationReference = DB6ADF811C23617500D77BF1 /* Framework.xcconfig */; buildSettings = { SDKROOT = macosx; - SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -812,7 +795,6 @@ buildSettings = { CLANG_ENABLE_CODE_COVERAGE = NO; SDKROOT = macosx; - SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Freddy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Freddy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Freddy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme index 052f726..1d38db2 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/Freddy.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -71,7 +70,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme index 994c625..2e1c8c6 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/MobileFreddy.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -71,7 +70,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme index 7c6d479..d91ca15 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/NanoFreddy.xcscheme @@ -1,6 +1,6 @@ @@ -37,7 +36,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme b/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme index 1e72f51..14026b6 100644 --- a/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme +++ b/Freddy.xcodeproj/xcshareddata/xcschemes/TVFreddy.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -71,7 +70,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" From 5a248dc4614468abe5aeb1cec5fd737c1d06ccd1 Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Fri, 1 Jun 2018 19:12:45 -0400 Subject: [PATCH 14/19] Set Swift version to 3.2 for CI and pods --- .swift-version | 2 +- Freddy.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.swift-version b/.swift-version index 9f55b2c..a3ec5a4 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +3.2 diff --git a/Freddy.podspec b/Freddy.podspec index 9a96351..81538ab 100644 --- a/Freddy.podspec +++ b/Freddy.podspec @@ -19,6 +19,7 @@ Pod::Spec.new do |s| "John Gallagher" => "jgallagher@bignerdranch.com", "Zachary Waldowski" => "zachary@bignerdranch.com" } + s.swift_version = '3.2' s.ios.deployment_target = "8.0" s.osx.deployment_target = "10.10" s.watchos.deployment_target = "2.0" @@ -28,5 +29,4 @@ Pod::Spec.new do |s| s.source_files = "Sources/**/*.{h,swift}" s.requires_arc = true - s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.2' } end From 0b373a236d4b94a94775103eb7ba96e8511b24d0 Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Fri, 1 Jun 2018 19:14:15 -0400 Subject: [PATCH 15/19] Update gems for fastlane, cocoapods, etc. --- .ruby-version | 1 - Gemfile | 1 - Gemfile.lock | 382 ++++++++++++++++++--------------------------- fastlane/README.md | 16 +- 4 files changed, 169 insertions(+), 231 deletions(-) delete mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index c043eea..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.2.1 diff --git a/Gemfile b/Gemfile index 50e0d73..aa77317 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,4 @@ source 'https://rubygems.org' -ruby '2.2.1' gem 'fastlane' gem 'cocoapods' diff --git a/Gemfile.lock b/Gemfile.lock index c2ad0a8..55d0a26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,289 +1,222 @@ GEM remote: https://rubygems.org/ specs: - activesupport (4.2.7.1) + CFPropertyList (3.0.0) + activesupport (4.2.10) i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.4.0) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + atomos (0.1.2) babosa (1.0.2) - cert (1.4.2) - fastlane_core (>= 0.50.3, < 1.0.0) - spaceship (>= 0.32.0, < 1.0.0) - claide (1.0.0) - cocoapods (1.0.1) - activesupport (>= 4.0.2) - claide (>= 1.0.0, < 2.0) - cocoapods-core (= 1.0.1) - cocoapods-deintegrate (>= 1.0.0, < 2.0) - cocoapods-downloader (>= 1.0.0, < 2.0) + claide (1.0.2) + cocoapods (1.5.3) + activesupport (>= 4.0.2, < 5) + claide (>= 1.0.2, < 2.0) + cocoapods-core (= 1.5.3) + cocoapods-deintegrate (>= 1.0.2, < 2.0) + cocoapods-downloader (>= 1.2.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.0.0, < 2.0) - cocoapods-try (>= 1.0.0, < 2.0) - colored (~> 1.2) + cocoapods-trunk (>= 1.3.0, < 2.0) + cocoapods-try (>= 1.1.0, < 2.0) + colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (~> 0.3.0) - molinillo (~> 0.4.5) + fourflusher (~> 2.0.1) + gh_inspector (~> 1.0) + molinillo (~> 0.6.5) nap (~> 1.0) - xcodeproj (>= 1.1.0, < 2.0) - cocoapods-core (1.0.1) - activesupport (>= 4.0.2) + ruby-macho (~> 1.1) + xcodeproj (>= 1.5.7, < 2.0) + cocoapods-core (1.5.3) + activesupport (>= 4.0.2, < 6) fuzzy_match (~> 2.0.4) nap (~> 1.0) - cocoapods-deintegrate (1.0.1) - cocoapods-downloader (1.1.1) + cocoapods-deintegrate (1.0.2) + cocoapods-downloader (1.2.1) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) cocoapods-stats (1.0.0) - cocoapods-trunk (1.0.0) + cocoapods-trunk (1.3.0) nap (>= 0.8, < 2.0) - netrc (= 0.7.8) + netrc (~> 0.11) cocoapods-try (1.1.0) colored (1.2) - commander (4.4.0) + colored2 (3.1.2) + commander-fastlane (4.4.6) highline (~> 1.7.2) - credentials_manager (0.16.0) - colored - commander (>= 4.3.5) - highline (>= 1.7.1) - security - deliver (1.13.3) - credentials_manager (>= 0.16.0, < 1.0.0) - fastimage (~> 1.6) - fastlane_core (>= 0.50.3, < 1.0.0) - plist (~> 3.1.0) - spaceship (>= 0.31.6, < 1.0.0) - domain_name (0.5.20160826) + concurrent-ruby (1.0.5) + declarative (0.0.10) + declarative-option (0.1.0) + domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) - dotenv (2.1.1) + dotenv (2.4.0) + emoji_regex (0.1.1) escape (0.0.4) - excon (0.45.4) - faraday (0.9.2) + excon (0.62.0) + faraday (0.15.2) multipart-post (>= 1.2, < 3) faraday-cookie_jar (0.0.6) faraday (>= 0.7.4) http-cookie (~> 1.0.0) - faraday_middleware (0.10.0) - faraday (>= 0.7.4, < 0.10) - fastimage (1.6.8) - addressable (~> 2.3, >= 2.3.5) - fastlane (1.102.0) - activesupport (< 5) - addressable (~> 2.3) - bundler (~> 1.12) - cert (>= 1.4.1, < 2.0.0) - credentials_manager (>= 0.16.0, < 1.0.0) - deliver (>= 1.13.3, < 2.0.0) - fastlane_core (>= 0.50.2, < 1.0.0) - frameit (>= 2.7.0, < 3.0.0) - gym (>= 1.7.0, < 2.0.0) - krausefx-shenzhen (>= 0.14.10) - match (>= 0.6.3, < 1.0.0) - multipart-post (~> 2.0.0) - pem (>= 1.3.2, < 2.0.0) - pilot (>= 1.10.0, < 2.0.0) - plist (~> 3.1.0) - produce (>= 1.2.0, < 2.0.0) - scan (>= 0.11.3, < 2.0.0) - screengrab (>= 0.5.0, < 1.0.0) - sigh (>= 1.10.0, < 2.0.0) - slack-notifier (~> 1.3) - snapshot (>= 1.14.0, < 2.0.0) - spaceship (>= 0.32.0, < 1.0.0) - supply (>= 0.7.0, < 1.0.0) - terminal-notifier (~> 1.6.2) - terminal-table (~> 1.4.5) - word_wrap (~> 1.0.0) - xcode-install (~> 2.0.0) - xcodeproj (>= 0.20, < 2.0.0) - xcpretty (>= 0.2.1) - fastlane_core (0.52.0) - babosa + faraday_middleware (0.12.2) + faraday (>= 0.7.4, < 1.0) + fastimage (2.1.3) + fastlane (2.96.1) + CFPropertyList (>= 2.3, < 4.0.0) + addressable (>= 2.3, < 3.0.0) + babosa (>= 1.0.2, < 2.0.0) + bundler (>= 1.12.0, < 2.0.0) colored - commander (>= 4.4.0, <= 5.0.0) - credentials_manager (>= 0.16.0, < 1.0.0) - excon (~> 0.45.0) - gh_inspector (>= 1.0.1, < 2.0.0) - highline (>= 1.7.2) - json - multi_json - plist (~> 3.1) - rubyzip (~> 1.1.6) - terminal-table (~> 1.4.5) - fourflusher (0.3.2) - frameit (2.7.0) - deliver (> 0.3) - fastimage (~> 1.6.3) - fastlane_core (>= 0.36.1, < 1.0.0) + commander-fastlane (>= 4.4.6, < 5.0.0) + dotenv (>= 2.1.1, < 3.0.0) + emoji_regex (~> 0.1) + excon (>= 0.45.0, < 1.0.0) + faraday (~> 0.9) + faraday-cookie_jar (~> 0.0.6) + faraday_middleware (~> 0.9) + fastimage (>= 2.1.0, < 3.0.0) + gh_inspector (>= 1.1.2, < 2.0.0) + google-api-client (>= 0.21.2, < 0.22.0) + highline (>= 1.7.2, < 2.0.0) + json (< 3.0.0) mini_magick (~> 4.5.1) + multi_json + multi_xml (~> 0.5) + multipart-post (~> 2.0.0) + plist (>= 3.1.0, < 4.0.0) + public_suffix (~> 2.0.0) + rubyzip (>= 1.1.0, < 2.0.0) + security (= 0.1.3) + simctl (~> 1.6.3) + slack-notifier (>= 2.0.0, < 3.0.0) + terminal-notifier (>= 1.6.2, < 2.0.0) + terminal-table (>= 1.4.5, < 2.0.0) + tty-screen (>= 0.6.3, < 1.0.0) + tty-spinner (>= 0.8.0, < 1.0.0) + word_wrap (~> 1.0.0) + xcodeproj (>= 1.5.7, < 2.0.0) + xcpretty (>= 0.2.4, < 1.0.0) + xcpretty-travis-formatter (>= 0.0.3) + ffi (1.9.23) + fourflusher (2.0.1) fuzzy_match (2.0.4) - gh_inspector (1.0.2) - google-api-client (0.9.13) - addressable (~> 2.3) - googleauth (~> 0.5) - httpclient (~> 2.7) - hurley (~> 0.1) - memoist (~> 0.11) - mime-types (>= 1.6) - representable (~> 2.3.0) - retriable (~> 2.0) - googleauth (0.5.1) - faraday (~> 0.9) - jwt (~> 1.4) + gh_inspector (1.1.3) + google-api-client (0.21.2) + addressable (~> 2.5, >= 2.5.1) + googleauth (>= 0.5, < 0.7.0) + httpclient (>= 2.8.1, < 3.0) + mime-types (~> 3.0) + representable (~> 3.0) + retriable (>= 2.0, < 4.0) + googleauth (0.6.2) + faraday (~> 0.12) + jwt (>= 1.4, < 3.0) logging (~> 2.0) memoist (~> 0.12) multi_json (~> 1.11) os (~> 0.9) signet (~> 0.7) - gym (1.9.0) - fastlane_core (>= 0.51.0, < 1.0.0) - plist - rubyzip (>= 1.1.7) - terminal-table - xcpretty (>= 0.2.1) - highline (1.7.8) - http-cookie (1.0.2) + highline (1.7.10) + http-cookie (1.0.3) domain_name (~> 0.5) - httpclient (2.8.2.4) - hurley (0.2) - i18n (0.7.0) - jazzy (0.7.1) + httpclient (2.8.3) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jazzy (0.9.3) cocoapods (~> 1.0) mustache (~> 0.99) open4 redcarpet (~> 3.2) - rouge (~> 1.5) + rouge (>= 2.0.6, < 4.0) sass (~> 3.4) sqlite3 (~> 1.3) - xcinvoke (~> 0.2.1) - json (1.8.3) - jwt (1.5.4) - krausefx-shenzhen (0.14.10) - commander (>= 4.3, < 5.0) - dotenv (>= 0.7) - faraday (~> 0.9) - faraday_middleware (~> 0.9) - highline (>= 1.7.2) - json (~> 1.8) - net-sftp (~> 2.1.2) - plist (~> 3.1.0) - rubyzip (~> 1.1) - security (~> 0.1.3) - terminal-table (~> 1.4.5) - liferaft (0.0.4) + xcinvoke (~> 0.3.0) + json (2.1.0) + jwt (2.1.0) + liferaft (0.0.6) little-plugger (1.1.4) - logging (2.1.0) + logging (2.2.2) little-plugger (~> 1.1) multi_json (~> 1.10) - match (0.6.4) - cert (>= 1.4.1, < 2.0.0) - credentials_manager (>= 0.16.0, < 1.0.0) - fastlane_core (>= 0.50.3, < 1.0.0) - security - sigh (>= 1.10.2, < 2.0.0) - spaceship (>= 0.31.10, < 1.0.0) - memoist (0.15.0) + memoist (0.16.0) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_magick (4.5.1) - minitest (5.9.0) - molinillo (0.4.5) - multi_json (1.12.1) - multi_xml (0.5.5) + minitest (5.11.3) + molinillo (0.6.5) + multi_json (1.13.1) + multi_xml (0.6.0) multipart-post (2.0.0) mustache (0.99.8) + nanaimo (0.2.5) nap (1.1.0) - net-sftp (2.1.2) - net-ssh (>= 2.6.5) - net-ssh (3.2.0) - netrc (0.7.8) + naturally (2.1.0) + netrc (0.11.0) open4 (1.3.4) os (0.9.6) - pem (1.3.2) - fastlane_core (>= 0.43.1, < 1.0.0) - spaceship (>= 0.26.2, < 1.0.0) - pilot (1.10.0) - credentials_manager (>= 0.3.0) - fastlane_core (>= 0.46.2, < 1.0.0) - spaceship (>= 0.29.0, < 1.0.0) - terminal-table (~> 1.4.5) - plist (3.1.0) - produce (1.2.0) - fastlane_core (>= 0.30.0, < 1.0.0) - spaceship (>= 0.31.1, < 1.0.0) - redcarpet (3.3.4) - representable (2.3.0) - uber (~> 0.0.7) - retriable (2.1.0) - rouge (1.11.1) - rubyzip (1.1.7) - sass (3.4.22) - scan (0.12.1) - fastlane_core (>= 0.51.0, < 1.0.0) - slack-notifier (~> 1.3) - terminal-table - xcpretty (>= 0.2.1) - xcpretty-travis-formatter (>= 0.0.3) - screengrab (0.5.2) - fastlane_core (>= 0.50.3, < 1.0.0) + plist (3.4.0) + public_suffix (2.0.5) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + redcarpet (3.4.0) + representable (3.0.4) + declarative (< 0.1.0) + declarative-option (< 0.2.0) + uber (< 0.2.0) + retriable (3.1.1) + rouge (2.0.7) + ruby-macho (1.1.0) + rubyzip (1.2.1) + sass (3.5.6) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) security (0.1.3) - sigh (1.10.2) - fastlane_core (>= 0.36.1, < 1.0.0) - plist (~> 3.1) - spaceship (>= 0.29.1, < 1.0.0) - signet (0.7.3) + signet (0.8.1) addressable (~> 2.3) faraday (~> 0.9) - jwt (~> 1.5) + jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - slack-notifier (1.5.1) - snapshot (1.14.0) - fastimage (~> 1.6.3) - fastlane_core (>= 0.50.3, < 1.0.0) - plist (~> 3.1.0) - xcpretty (>= 0.2.1) - spaceship (0.32.1) - colored - credentials_manager (>= 0.16.0) - faraday (~> 0.9) - faraday-cookie_jar (~> 0.0.6) - faraday_middleware (~> 0.9) - fastimage (~> 1.6) - multi_xml (~> 0.5) - plist (~> 3.1) - sqlite3 (1.3.11) - supply (0.7.1) - credentials_manager (>= 0.15.0) - fastlane_core (>= 0.43.4) - google-api-client (~> 0.9.1) - terminal-notifier (1.6.3) - terminal-table (1.4.5) - thread_safe (0.3.5) - tzinfo (1.2.2) + simctl (1.6.4) + CFPropertyList + naturally + slack-notifier (2.3.2) + sqlite3 (1.3.13) + terminal-notifier (1.8.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thread_safe (0.3.6) + tty-cursor (0.5.0) + tty-screen (0.6.4) + tty-spinner (0.8.0) + tty-cursor (>= 0.5.0) + tzinfo (1.2.5) thread_safe (~> 0.1) - uber (0.0.15) + uber (0.1.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.2) + unf_ext (0.0.7.5) + unicode-display_width (1.3.3) word_wrap (1.0.0) - xcinvoke (0.2.1) - liferaft (~> 0.0.4) - xcode-install (2.0.5) - claide (>= 0.9.1, < 1.1.0) - spaceship (>= 0.25.1, < 1.0.0) - xcodeproj (1.3.1) - activesupport (>= 3) - claide (>= 1.0.0, < 2.0) - colored (~> 1.2) - xcpretty (0.2.2) - rouge (~> 1.8) - xcpretty-travis-formatter (0.0.4) + xcinvoke (0.3.0) + liferaft (~> 0.0.6) + xcodeproj (1.5.9) + CFPropertyList (>= 2.3.3, < 4.0) + atomos (~> 0.1.2) + claide (>= 1.0.2, < 2.0) + colored2 (~> 3.1) + nanaimo (~> 0.2.5) + xcpretty (0.2.8) + rouge (~> 2.0.7) + xcpretty-travis-formatter (1.0.0) xcpretty (~> 0.2, >= 0.0.7) PLATFORMS @@ -295,8 +228,5 @@ DEPENDENCIES jazzy xcpretty -RUBY VERSION - ruby 2.2.1p85 - BUNDLED WITH - 1.12.5 + 1.16.2 diff --git a/fastlane/README.md b/fastlane/README.md index e16f5c8..1177601 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -1,9 +1,19 @@ fastlane documentation ================ # Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +``` +xcode-select --install ``` -sudo gem install fastlane + +Install _fastlane_ using +``` +[sudo] gem install fastlane -NV ``` +or alternatively using `brew cask install fastlane` + # Available Actions ### travis ``` @@ -44,5 +54,5 @@ Create docs ---- This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. -More information about fastlane can be found on [https://fastlane.tools](https://fastlane.tools). -The documentation of fastlane can be found on [GitHub](https://github.com/fastlane/fastlane/tree/master/fastlane). \ No newline at end of file +More information about fastlane can be found on [fastlane.tools](https://fastlane.tools). +The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools). From ac22aa0dc63637144e7db5f27d7aa2f193c69691 Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Fri, 1 Jun 2018 19:21:04 -0400 Subject: [PATCH 16/19] Fix order of cast to preserve boolean conversion on Darwin --- Sources/JSONParsing.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/JSONParsing.swift b/Sources/JSONParsing.swift index 6623371..e30025e 100644 --- a/Sources/JSONParsing.swift +++ b/Sources/JSONParsing.swift @@ -56,14 +56,14 @@ extension JSONSerialization: JSONParserType { /// - returns: An instance of `JSON` matching the JSON given to the function. public static func makeJSON(with object: Any) -> JSON { switch object { + case let n as Bool: + return .bool(n) + case let n as Int: return .int(n) case let n as Double: return .double(n) - - case let n as Bool: - return .bool(n) case let arr as [Any]: return makeJSONArray(arr) From 0cbb169b6ccc4f7e22ff67cbe25a11064cd6a3df Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Fri, 1 Jun 2018 19:36:21 -0400 Subject: [PATCH 17/19] Restore Darwin fallback behavior for truncating NSNumber --- Sources/JSONParsing.swift | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Sources/JSONParsing.swift b/Sources/JSONParsing.swift index e30025e..235b769 100644 --- a/Sources/JSONParsing.swift +++ b/Sources/JSONParsing.swift @@ -55,6 +55,22 @@ extension JSONSerialization: JSONParserType { /// - parameter object: The instance of `Any` returned from serializing the JSON. /// - returns: An instance of `JSON` matching the JSON given to the function. public static func makeJSON(with object: Any) -> JSON { + #if !swift(>=3.2) && (os(macOS) || os(iOS) || os(macOS) || os(tvOS)) + if let n = object as? NSNumber { + let numberType = CFNumberGetType(n) + switch numberType { + case .charType: + return .bool(n.boolValue) + + case .shortType, .intType, .longType, .cfIndexType, .nsIntegerType, .sInt8Type, .sInt16Type, .sInt32Type: + return .int(n.intValue) + + default: + return .double(n.doubleValue) + } + } + #endif + switch object { case let n as Bool: return .bool(n) @@ -65,13 +81,16 @@ extension JSONSerialization: JSONParserType { case let n as Double: return .double(n) + case let n as NSNumber: + return .double(n.doubleValue) + case let arr as [Any]: return makeJSONArray(arr) - case let dict as [Swift.String: Any]: + case let dict as [String: Any]: return makeJSONDictionary(dict) - case let s as Swift.String: + case let s as String: return .string(s) default: From 83dfe83a41c4922ab2201370cdf23b0068ae1ca9 Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Fri, 1 Jun 2018 22:58:18 -0400 Subject: [PATCH 18/19] Address compatibility with Swift 3 from removing ArithmeticOverflow --- Sources/JSONParser.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/JSONParser.swift b/Sources/JSONParser.swift index 6e5ce61..fd521bd 100644 --- a/Sources/JSONParser.swift +++ b/Sources/JSONParser.swift @@ -442,6 +442,12 @@ public struct JSONParser { var sign = Sign.positive var parser = parser var value = 0 + + #if swift(>=3.2) + let noOverflow = false + #else + let noOverflow = ArithmeticOverflow.none + #endif // This would be more natural as `while true { ... }` with a meaningful .Done case, // but that causes compile time explosion in Swift 2.2. :-| @@ -457,11 +463,12 @@ public struct JSONParser { case .preDecimalDigits: let start = parser.start try parser.parsePreDecimalDigits { c in - guard case let (exponent, false) = 10.multipliedReportingOverflow(by: value) else { + + guard case (let exponent, noOverflow) = 10.multipliedReportingOverflow(by: value) else { throw InternalError.numberOverflow(offset: start) } - guard case let (newValue, false) = exponent.addingReportingOverflow(Int(c - Literal.zero)) else { + guard case (let newValue, noOverflow) = exponent.addingReportingOverflow(Int(c - Literal.zero)) else { throw InternalError.numberOverflow(offset: start) } @@ -481,7 +488,7 @@ public struct JSONParser { } } - guard case let (signedValue, false) = sign.rawValue.multipliedReportingOverflow(by: value) else { + guard case (let signedValue, noOverflow) = sign.rawValue.multipliedReportingOverflow(by: value) else { throw InternalError.numberOverflow(offset: parser.start) } From 70c2ef1323b69d24f3dac9bd3565e895a660a72c Mon Sep 17 00:00:00 2001 From: Zachary Waldowski Date: Fri, 1 Jun 2018 19:42:57 -0400 Subject: [PATCH 19/19] Address Swift deprecations --- Sources/JSONDecodable.swift | 28 +++++++++++++------ Sources/JSONEncodingDetector.swift | 15 ++++++---- Tests/FreddyTests/JSONDecodableTests.swift | 4 +-- .../JSONEncodingDetectorTests.swift | 8 +++++- Tests/FreddyTests/JSONParserTests.swift | 4 +++ Tests/FreddyTests/JSONSerializingTests.swift | 6 ++-- Tests/FreddyTests/JSONSubscriptingTests.swift | 6 ++-- 7 files changed, 49 insertions(+), 22 deletions(-) diff --git a/Sources/JSONDecodable.swift b/Sources/JSONDecodable.swift index 89c7f14..212c312 100644 --- a/Sources/JSONDecodable.swift +++ b/Sources/JSONDecodable.swift @@ -41,6 +41,25 @@ extension Double: JSONDecodable { } extension Int: JSONDecodable { + + private init?(exactly string: String) { + #if swift(>=3.2) + let characters = string + #else + let characters = string.characters + #endif + + if let int = Int(string) { + self = int + } else if let double = Double(string), + let decimalSeparator = characters.index(of: "."), + let int = Int(String(characters.prefix(upTo: decimalSeparator))), + double == Double(int) { + self = int + } else { + return nil + } + } /// An initializer to create an instance of `Int` from a `JSON` value. /// - parameter json: An instance of `JSON`. @@ -48,18 +67,11 @@ extension Int: JSONDecodable { /// an instance of `Int` cannot be created from the `JSON` value that was /// passed to this initializer. public init(json: JSON) throws { - if case let .double(double) = json, double <= Double(Int.max) { self = Int(double) } else if case let .int(int) = json { self = int - } else if case let .string(string) = json, let int = Int(string) { - self = int - } else if case let .string(string) = json, - let double = Double(string), - let decimalSeparator = string.characters.index(of: "."), - let int = Int(String(string.characters.prefix(upTo: decimalSeparator))), - double == Double(int) { + } else if case let .string(string) = json, let int = Int(exactly: string) { self = int } else { throw JSON.Error.valueNotConvertible(value: json, to: Int.self) diff --git a/Sources/JSONEncodingDetector.swift b/Sources/JSONEncodingDetector.swift index 84410f1..be25b08 100644 --- a/Sources/JSONEncodingDetector.swift +++ b/Sources/JSONEncodingDetector.swift @@ -26,7 +26,13 @@ public struct JSONEncodingDetector { //// The Unicode encodings supported by JSONParser.swift public static let supportedEncodings: [Encoding] = [.utf8] - typealias ByteStreamPrefixInformation = (encoding: Encoding, byteOrderMarkLength: Int) + public typealias ByteStreamPrefixInformation = (encoding: Encoding, byteOrderMarkLength: Int) + + #if swift(>=3.3) + public typealias ByteStreamPrefix = Slice> + #else + public typealias ByteStreamPrefix = RandomAccessSlice> + #endif //// Attempts to detect the Unicode encoding used for a given set of data. //// @@ -56,13 +62,12 @@ public struct JSONEncodingDetector { //// //// - parameter header: The front Slice of data being read and evaluated. //// - returns: A tuple containing the detected Unicode encoding and the lenght of the byte order mark. - static func detectEncoding(_ header: RandomAccessSlice>) -> ByteStreamPrefixInformation { - + public static func detectEncoding(_ header: ByteStreamPrefix) -> ByteStreamPrefixInformation { guard let prefix = prefixFromHeader(header) else { return (.utf8, 0) } - if let prefixInfo = JSONEncodingDetector.encodingFromBOM(prefix) { + if let prefixInfo = encodingFromBOM(prefix) { return prefixInfo } else { switch prefix { @@ -82,7 +87,7 @@ public struct JSONEncodingDetector { private typealias EncodingBytePrefix = (UInt8, UInt8, UInt8?, UInt8?) - private static func prefixFromHeader(_ header: RandomAccessSlice>) -> EncodingBytePrefix? { + private static func prefixFromHeader(_ header: ByteStreamPrefix) -> EncodingBytePrefix? { if header.count >= 4 { return(header[0], header[1], header[2], header[3]) } else if header.count >= 2 { diff --git a/Tests/FreddyTests/JSONDecodableTests.swift b/Tests/FreddyTests/JSONDecodableTests.swift index 13debcf..f81c592 100644 --- a/Tests/FreddyTests/JSONDecodableTests.swift +++ b/Tests/FreddyTests/JSONDecodableTests.swift @@ -228,7 +228,7 @@ class JSONDecodableTests: XCTestCase { let oneTwoThreeJSON: JSON = [1,2,3] do { - let decodedOneTwoThree = try oneTwoThreeJSON.decodedArray(type: Swift.Int) + let decodedOneTwoThree = try oneTwoThreeJSON.decodedArray(type: Swift.Int.self) XCTAssertEqual(decodedOneTwoThree, [1,2,3], "`decodedOneTwoThree` should be equal to `[1,2,3]`.") } catch { XCTFail("`decodedOneTwoThree` should be equal to `[1,2,3]`.") @@ -239,7 +239,7 @@ class JSONDecodableTests: XCTestCase { let oneTwoThreeJSON: JSON = ["one": 1, "two": 2, "three": 3] do { - let decodedOneTwoThree = try oneTwoThreeJSON.decodedDictionary(type: Swift.Int) + let decodedOneTwoThree = try oneTwoThreeJSON.decodedDictionary(type: Swift.Int.self) XCTAssertEqual(decodedOneTwoThree, ["one": 1, "two": 2, "three": 3], "`decodedOneTwoThree` should be equal to `[\"one\": 1, \"two\": 2, \"three\": 3]`.") } catch { XCTFail("`decodedOneTwoThree` should be equal to `[\"one\": 1, \"two\": 2, \"three\": 3]`.") diff --git a/Tests/FreddyTests/JSONEncodingDetectorTests.swift b/Tests/FreddyTests/JSONEncodingDetectorTests.swift index d41cc09..aeb8352 100644 --- a/Tests/FreddyTests/JSONEncodingDetectorTests.swift +++ b/Tests/FreddyTests/JSONEncodingDetectorTests.swift @@ -107,7 +107,13 @@ struct JSONEncodingUTFTestFixtures { } } - func withPrefixSlice(_ encoding: JSONEncodingDetector.Encoding, includeBOM: Bool, body: (RandomAccessSlice>) throws -> R) rethrows -> R { + #if swift(>=3.3) + public typealias PrefixSlice = Slice> + #else + public typealias PrefixSlice = RandomAccessSlice> + #endif + + func withPrefixSlice(_ encoding: JSONEncodingDetector.Encoding, includeBOM: Bool, body: (PrefixSlice) throws -> R) rethrows -> R { let array = hexArray(encoding, includeBOM: includeBOM) return try array.withUnsafeBufferPointer { try body($0.prefix(4)) diff --git a/Tests/FreddyTests/JSONParserTests.swift b/Tests/FreddyTests/JSONParserTests.swift index 5223beb..fbf5be5 100644 --- a/Tests/FreddyTests/JSONParserTests.swift +++ b/Tests/FreddyTests/JSONParserTests.swift @@ -200,7 +200,11 @@ class JSONParserTests: XCTestCase { ] { do { let value = try JSONParser.parse(string).getDouble() + #if swift(>=3.2) + XCTAssertEqual(value, shouldBeDouble, accuracy: .ulpOfOne) + #else XCTAssertEqualWithAccuracy(value, shouldBeDouble, accuracy: DBL_EPSILON) + #endif } catch { XCTFail("Unexpected error: \(error)") } diff --git a/Tests/FreddyTests/JSONSerializingTests.swift b/Tests/FreddyTests/JSONSerializingTests.swift index 2136d0d..1654ff9 100644 --- a/Tests/FreddyTests/JSONSerializingTests.swift +++ b/Tests/FreddyTests/JSONSerializingTests.swift @@ -12,9 +12,9 @@ class JSONSerializingTests: XCTestCase { XCTAssertGreaterThan(data.count, 0, "There should be data.") } - func testThatJSONCanBeSerializedToString() { - let string = try! json.serializeString() - XCTAssertGreaterThan(string.characters.count, 0, "There should be characters.") + func testThatJSONCanBeSerializedToString() throws { + let string = try json.serializeString() + XCTAssertFalse(string.isEmpty, "There should be characters.") } func testThatJSONDataIsEqual() { diff --git a/Tests/FreddyTests/JSONSubscriptingTests.swift b/Tests/FreddyTests/JSONSubscriptingTests.swift index f34142c..d1ed344 100644 --- a/Tests/FreddyTests/JSONSubscriptingTests.swift +++ b/Tests/FreddyTests/JSONSubscriptingTests.swift @@ -306,7 +306,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try residentJSON.decode(at: "residents", 1, "name", "initial", type: Resident.self) } catch JSON.Error.unexpectedSubscript(let type) { - XCTAssert(type == Swift.String, "The dictionary at index 1 should not be subscriptable by: \(type).") + XCTAssert(type == Swift.String.self, "The dictionary at index 1 should not be subscriptable by: \(type).") } catch { XCTFail("This should not be: \(error).") } @@ -392,7 +392,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try json.getInt(at: "people", 0, "name") } catch let JSON.Error.valueNotConvertible(value, to) { - XCTAssert(to == Swift.Int, "The error should be due the value not being an `Int` case, but was \(to).") + XCTAssert(to == Swift.Int.self, "The error should be due the value not being an `Int` case, but was \(to).") XCTAssert(value == "Matt Mathias", "The error should be due the value being the String 'Matt Mathias', but was \(value).") } catch { XCTFail("The error should be due to `name` not being convertible to `int`, but was: \(error).") @@ -403,7 +403,7 @@ class JSONSubscriptingTests: XCTestCase { do { _ = try json.getString(at: "people", "name") } catch JSON.Error.unexpectedSubscript(let type) { - XCTAssert(type == Swift.String, "The error should be due the value not being subscriptable with string `String` case, but was \(type).") + XCTAssert(type == Swift.String.self, "The error should be due the value not being subscriptable with string `String` case, but was \(type).") } catch { XCTFail("The error should be due to the `people` `Array` not being subscriptable with `String`s, but was: \(error).") }