Skip to content

Commit

Permalink
🔧 migrated to Swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krüger committed Apr 16, 2019
1 parent fa20523 commit 9d31d35
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
16 changes: 6 additions & 10 deletions JSONCodable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@
TargetAttributes = {
9E455BF61BCE185B00070A4F = {
CreatedOnToolsVersion = 7.0.1;
LastSwiftMigration = 1010;
LastSwiftMigration = 1020;
};
9EDB39051B59D00B00C63019 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 1010;
LastSwiftMigration = 1020;
};
};
};
Expand Down Expand Up @@ -385,8 +385,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -429,8 +428,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -486,8 +484,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -542,8 +539,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
VALIDATE_PRODUCT = YES;
Expand Down
4 changes: 2 additions & 2 deletions JSONCodable/JSONDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public protocol JSONDecodable {

public extension JSONDecodable {
/// initialize with top-level Array JSON data
public init(object: [JSONObject]) throws {
init(object: [JSONObject]) throws {
// use empty string key
try self.init(object:["": object])
}

public init?(optional: JSONObject) {
init?(optional: JSONObject) {
do {
try self.init(object: optional)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion JSONCodable/JSONEncodable+Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public extension Mirror {
- returns: array of Tuples containing the label and value for each property
*/
public func getAllProperties() -> [(label: String?, value: Any)] {
func getAllProperties() -> [(label: String?, value: Any)] {
var children: [(label: String?, value: Any)] = []
for element in self.children {
children.append(element)
Expand Down
4 changes: 2 additions & 2 deletions JSONCodable/JSONEncodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public extension JSONEncodable {
public extension Array { //where Element: JSONEncodable {
private var wrapped: [Any] { return self.map{$0} }

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

public extension Dictionary {//where Key: String, Value: JSONEncodable {
public func toJSON() throws -> Any {
func toJSON() throws -> Any {
var result: [String: Any] = [:]
for (k, item) in self {
if let item = item as? JSONEncodable {
Expand Down
4 changes: 2 additions & 2 deletions JSONCodable/JSONString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

public extension JSONEncodable {
public func toJSONString() throws -> String {
func toJSONString() throws -> String {
switch self {
case let str as String:
return escapeJSONString(str)
Expand Down Expand Up @@ -45,7 +45,7 @@ private func escapeJSONString(_ str: String) -> String {
}

public extension Optional where Wrapped: JSONEncodable {
public func toJSONString() throws -> String {
func toJSONString() throws -> String {
switch self {
case let .some(jsonEncodable):
return try jsonEncodable.toJSONString()
Expand Down
16 changes: 15 additions & 1 deletion JSONCodableTests/EncodeNestingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ class EncodeNestingTests: XCTestCase {
XCTFail()
return
}
XCTAssert(String(describing:json1) == String(describing:propertyItemArray), "failed to convert to \(propertyItemArray)")

XCTAssertEqual(json1["class"] as! String, propertyItemArray["class"] as! String)
XCTAssertEqual(json1["class"] as! String, propertyItemArray["class"] as! String)

let properties = propertyItemArray["properties"] as! [String: Any]
let properties1 = json1["properties"] as! [String: Any]
XCTAssertEqual(properties1["name"] as! String, properties["name"] as! String)

let location = properties["location"] as! [String: Any]
let location1 = properties1["location"] as! [String: Any]

let coord = location["coord"] as! [String: Any]
let coord1 = location1["coord"] as! [String: Any]
XCTAssertEqual(coord["lat"] as! Double, coord1["lat"] as! Double)
XCTAssertEqual(coord["long"] as! Double, coord1["long"] as! Double)
}
}

0 comments on commit 9d31d35

Please sign in to comment.