Skip to content

Commit 9d31d35

Browse files
author
Florian Krüger
committed
🔧 migrated to Swift 5
1 parent fa20523 commit 9d31d35

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

JSONCodable.xcodeproj/project.pbxproj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@
243243
TargetAttributes = {
244244
9E455BF61BCE185B00070A4F = {
245245
CreatedOnToolsVersion = 7.0.1;
246-
LastSwiftMigration = 1010;
246+
LastSwiftMigration = 1020;
247247
};
248248
9EDB39051B59D00B00C63019 = {
249249
CreatedOnToolsVersion = 7.0;
250-
LastSwiftMigration = 1010;
250+
LastSwiftMigration = 1020;
251251
};
252252
};
253253
};
@@ -385,8 +385,7 @@
385385
PRODUCT_NAME = "$(TARGET_NAME)";
386386
SDKROOT = macosx;
387387
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
388-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
389-
SWIFT_VERSION = 4.2;
388+
SWIFT_VERSION = 5.0;
390389
};
391390
name = Debug;
392391
};
@@ -429,8 +428,7 @@
429428
PRODUCT_NAME = "$(TARGET_NAME)";
430429
SDKROOT = macosx;
431430
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
432-
SWIFT_SWIFT3_OBJC_INFERENCE = On;
433-
SWIFT_VERSION = 4.2;
431+
SWIFT_VERSION = 5.0;
434432
};
435433
name = Release;
436434
};
@@ -486,8 +484,7 @@
486484
SDKROOT = iphoneos;
487485
SKIP_INSTALL = YES;
488486
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
489-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
490-
SWIFT_VERSION = 4.2;
487+
SWIFT_VERSION = 5.0;
491488
TARGETED_DEVICE_FAMILY = "1,2,3,4";
492489
TVOS_DEPLOYMENT_TARGET = 9.0;
493490
VERSIONING_SYSTEM = "apple-generic";
@@ -542,8 +539,7 @@
542539
SDKROOT = iphoneos;
543540
SKIP_INSTALL = YES;
544541
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
545-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
546-
SWIFT_VERSION = 4.2;
542+
SWIFT_VERSION = 5.0;
547543
TARGETED_DEVICE_FAMILY = "1,2,3,4";
548544
TVOS_DEPLOYMENT_TARGET = 9.0;
549545
VALIDATE_PRODUCT = YES;

JSONCodable/JSONDecodable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public protocol JSONDecodable {
5454

5555
public extension JSONDecodable {
5656
/// initialize with top-level Array JSON data
57-
public init(object: [JSONObject]) throws {
57+
init(object: [JSONObject]) throws {
5858
// use empty string key
5959
try self.init(object:["": object])
6060
}
6161

62-
public init?(optional: JSONObject) {
62+
init?(optional: JSONObject) {
6363
do {
6464
try self.init(object: optional)
6565
} catch {

JSONCodable/JSONEncodable+Mirror.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public extension Mirror {
1212

1313
- returns: array of Tuples containing the label and value for each property
1414
*/
15-
public func getAllProperties() -> [(label: String?, value: Any)] {
15+
func getAllProperties() -> [(label: String?, value: Any)] {
1616
var children: [(label: String?, value: Any)] = []
1717
for element in self.children {
1818
children.append(element)

JSONCodable/JSONEncodable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public extension JSONEncodable {
105105
public extension Array { //where Element: JSONEncodable {
106106
private var wrapped: [Any] { return self.map{$0} }
107107

108-
public func toJSON() throws -> Any {
108+
func toJSON() throws -> Any {
109109
var results: [Any] = []
110110
for item in self.wrapped {
111111
if let item = item as? JSONEncodable {
@@ -122,7 +122,7 @@ public extension Array { //where Element: JSONEncodable {
122122
// Dictionary convenience methods
123123

124124
public extension Dictionary {//where Key: String, Value: JSONEncodable {
125-
public func toJSON() throws -> Any {
125+
func toJSON() throws -> Any {
126126
var result: [String: Any] = [:]
127127
for (k, item) in self {
128128
if let item = item as? JSONEncodable {

JSONCodable/JSONString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
public extension JSONEncodable {
12-
public func toJSONString() throws -> String {
12+
func toJSONString() throws -> String {
1313
switch self {
1414
case let str as String:
1515
return escapeJSONString(str)
@@ -45,7 +45,7 @@ private func escapeJSONString(_ str: String) -> String {
4545
}
4646

4747
public extension Optional where Wrapped: JSONEncodable {
48-
public func toJSONString() throws -> String {
48+
func toJSONString() throws -> String {
4949
switch self {
5050
case let .some(jsonEncodable):
5151
return try jsonEncodable.toJSONString()

JSONCodableTests/EncodeNestingTests.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ class EncodeNestingTests: XCTestCase {
2828
XCTFail()
2929
return
3030
}
31-
XCTAssert(String(describing:json1) == String(describing:propertyItemArray), "failed to convert to \(propertyItemArray)")
31+
32+
XCTAssertEqual(json1["class"] as! String, propertyItemArray["class"] as! String)
33+
XCTAssertEqual(json1["class"] as! String, propertyItemArray["class"] as! String)
34+
35+
let properties = propertyItemArray["properties"] as! [String: Any]
36+
let properties1 = json1["properties"] as! [String: Any]
37+
XCTAssertEqual(properties1["name"] as! String, properties["name"] as! String)
38+
39+
let location = properties["location"] as! [String: Any]
40+
let location1 = properties1["location"] as! [String: Any]
41+
42+
let coord = location["coord"] as! [String: Any]
43+
let coord1 = location1["coord"] as! [String: Any]
44+
XCTAssertEqual(coord["lat"] as! Double, coord1["lat"] as! Double)
45+
XCTAssertEqual(coord["long"] as! Double, coord1["long"] as! Double)
3246
}
3347
}

0 commit comments

Comments
 (0)