Skip to content

Commit

Permalink
Swift 4.1 and Xcode 9.3 support - v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
s4cha committed Apr 10, 2018
1 parent 0c3ba3d commit 9f9ef35
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 42 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ disabled_rules:
- missing_docs
- conditional_binding_cascade
- force_unwrapping
- identifier_name
opt_in_rules:
- empty_count
- missing_docs
Expand Down
Binary file modified Arrow.framework.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Arrow.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Arrow'
s.version = "4.0.0"
s.version = "4.1.0"
s.summary = "Elegant JSON Parsing in Swift"
s.homepage = "https://github.com/freshOS/Arrow"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
6 changes: 5 additions & 1 deletion Arrow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Sacha Durand Saint Omer";
TargetAttributes = {
99C292E61B24AD5E0008C32B = {
Expand Down Expand Up @@ -408,12 +408,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -463,12 +465,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
4 changes: 1 addition & 3 deletions Arrow.xcodeproj/xcshareddata/xcschemes/Arrow.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
14 changes: 7 additions & 7 deletions ArrowTests/ArrayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ArrayContainer {
var optionalWeekdays: [WeekDay]?
}

extension ArrayContainer:ArrowParsable {
extension ArrayContainer: ArrowParsable {

mutating func deserialize(_ json: JSON) {
phoneNumbers <-- json["phoneNumbers"]
Expand Down Expand Up @@ -58,7 +58,7 @@ class ArrayTests: XCTestCase {
XCTAssertEqual(arrayContainer.phoneNumbers[1].number, "0908070656")
XCTAssertEqual(arrayContainer.phoneNumbers[2].number, "0916570656")
} else {
XCTFail()
XCTFail("Parsing ArrayOf Custom Models Fails")
}
}

Expand All @@ -81,7 +81,7 @@ class ArrayTests: XCTestCase {
XCTAssertEqual(arrayContainer.strings[1], "two")
XCTAssertEqual(arrayContainer.strings[2], "three")
} else {
XCTFail()
XCTFail("Parsing an array of strings fails")
}
}

Expand All @@ -92,7 +92,7 @@ class ArrayTests: XCTestCase {
XCTAssertEqual(arrayContainer.ints[1], 2)
XCTAssertEqual(arrayContainer.ints[2], 3)
} else {
XCTFail()
XCTFail("Parsing an array of ints fails")
}
}

Expand All @@ -103,7 +103,7 @@ class ArrayTests: XCTestCase {
XCTAssertEqual(arrayContainer.bools[1], false)
XCTAssertEqual(arrayContainer.bools[2], true)
} else {
XCTFail()
XCTFail("Parsing an array of bools fails")
}
}

Expand All @@ -122,7 +122,7 @@ class ArrayTests: XCTestCase {
XCTAssertEqual(arrayContainer.weekdays[1], WeekDay.wednesday)
XCTAssertEqual(arrayContainer.weekdays[2], WeekDay.friday)
} else {
XCTFail()
XCTFail("Parsing an array of enums fails")
}
}

Expand All @@ -133,7 +133,7 @@ class ArrayTests: XCTestCase {
XCTAssertEqual(arrayContainer.optionalWeekdays?[1], WeekDay.wednesday)
XCTAssertEqual(arrayContainer.optionalWeekdays?[2], WeekDay.friday)
} else {
XCTFail()
XCTFail("Parsing an array of optional enums fails")
}
}
}
12 changes: 6 additions & 6 deletions ArrowTests/DateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ class DateTests: XCTestCase {
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
if let date = df.date(from: "2013-06-07T16:38:40+02:00") {
XCTAssertEqualWithAccuracy(date.timeIntervalSinceReferenceDate, dateContainer.createdAt
XCTAssertEqual(date.timeIntervalSinceReferenceDate, dateContainer.createdAt
.timeIntervalSinceReferenceDate, accuracy: 0.1)
} else {
XCTFail()
XCTFail("Parsing a date fails")
}
}

func testParsingOptionalDate() {
let timestamp: TimeInterval = 392308720
if let d = dateContainer.optionalDate?.timeIntervalSinceReferenceDate {
XCTAssertEqualWithAccuracy(timestamp, d, accuracy: 0.1)
XCTAssertEqual(timestamp, d, accuracy: 0.1)
} else {
XCTFail()
XCTFail("Parsing an Optional Date fails")
}
}

Expand All @@ -50,7 +50,7 @@ class DateTests: XCTestCase {
aDate <-- json["created_at"]?.dateFormatter(df)
XCTAssertEqual(aDate, df.date(from: "2013-06-07T16:38:40+02:00"))
} else {
XCTFail()
XCTFail("Using a custom date Parser fails")
}
}

Expand All @@ -63,7 +63,7 @@ class DateTests: XCTestCase {
aDate <-- json["created_at"]
XCTAssertEqual(aDate, df.date(from: "2013-06-07T16:38:40+02:00"))
} else {
XCTFail()
XCTFail("Using a global date parser fails")
}

Arrow.setDateFormatter(nil)
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/NativeTypesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func jsonForName(_ name: String) -> JSON? {
let json = try? JSONSerialization
.jsonObject(with: jsonData,
options: .mutableContainers) as? NSDictionary,
let dic = json as? [String : Any] {
let dic = json as? [String: Any] {
return JSON(dic)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/StringCoercionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct CoercionContainer {
var cgfloatString: CGFloat = 0.0
}

extension CoercionContainer:ArrowParsable {
extension CoercionContainer: ArrowParsable {

mutating func deserialize(_ json: JSON) {
cgfloatString <-- json["floatString"]
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/mapping/CustomModelContainer+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Arrow

extension CustomModelContainer:ArrowParsable {
extension CustomModelContainer: ArrowParsable {

mutating func deserialize(_ json: JSON) {
stats <-- json["stats"]
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/mapping/DateContainer+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Arrow

extension DateContainer:ArrowParsable {
extension DateContainer: ArrowParsable {

mutating func deserialize(_ json: JSON) {
createdAt <-- json["created_at"]?.dateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/mapping/EnumContainer+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Arrow

extension EnumContainer:ArrowParsable {
extension EnumContainer: ArrowParsable {

mutating func deserialize(_ json: JSON) {
weekday <-- json["weekdayInt"]
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/mapping/Profile+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Arrow

extension Profile:ArrowParsable {
extension Profile: ArrowParsable {

mutating func deserialize(_ json: JSON) {
identifier <-- json["id"]
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/mapping/Stats+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Arrow

extension Stats:ArrowParsable {
extension Stats: ArrowParsable {

mutating func deserialize(_ json: JSON) {
numberOfFriends <-- json["numberOfFriends"]
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/mapping/StringContainer+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Arrow

extension StringContainer:ArrowParsable {
extension StringContainer: ArrowParsable {
mutating func deserialize(_ json: JSON) {
name <-- json["name"]
optionalName = nil
Expand Down
2 changes: 1 addition & 1 deletion ArrowTests/mapping/URLContainer+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Arrow

extension URLContainer:ArrowParsable {
extension URLContainer: ArrowParsable {

mutating func deserialize(_ json: JSON) {
link <-- json["link"]
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Build Status](https://www.bitrise.io/app/ffd8fe5df34624ff.svg?token=IahWn-RB5hTWzvBbcIktsQ)](https://www.bitrise.io/app/ffd8fe5df34624ff)
[![codebeat badge](https://codebeat.co/badges/f037ac0c-b3d9-4132-9fca-64150a908113)](https://codebeat.co/projects/github-com-freshos-arrow)
[![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/freshOS/Arrow/blob/master/LICENSE)
[![Release version](https://img.shields.io/badge/release-4.0-blue.svg)]()
![Release version](https://img.shields.io/github/release/freshos/then.svg)

[Reason](#reason) - [Example](#example) - [Installation](#installation)

Expand Down Expand Up @@ -239,6 +239,7 @@ if let collection = json.collection {
- Swift 2 -> version [**2.0.3**](https://github.com/freshOS/Arrow/releases/tag/2.0.3)
- Swift 3 -> version [**3.0.5**](https://github.com/freshOS/Arrow/releases/tag/3.0.5)
- Swift 4 -> version [**4.0.0**](https://github.com/freshOS/Arrow/releases/tag/4.0.0)
- Swift 4.1 -> version [**4.1.0**](https://github.com/freshOS/Arrow/releases/tag/4.1.0)

## Acknoledgments
This wouldn't exist without [YannickDot](https://github.com/YannickDot), [Damien-nd](https://github.com/damien-nd) and [maxkonovalov](https://github.com/maxkonovalov)
Expand All @@ -249,7 +250,7 @@ This wouldn't exist without [YannickDot](https://github.com/YannickDot), [Damien


### Backers
Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :)
Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :)

<a href="https://opencollective.com/freshos/backer/0/website" target="_blank"><img src="https://opencollective.com/freshos/backer/0/avatar.svg"></a>
<a href="https://opencollective.com/freshos/backer/1/website" target="_blank"><img src="https://opencollective.com/freshos/backer/1/avatar.svg"></a>
Expand Down Expand Up @@ -283,7 +284,7 @@ Like the project? Offer coffee or support us with a monthly donation and help us
<a href="https://opencollective.com/freshos/backer/29/website" target="_blank"><img src="https://opencollective.com/freshos/backer/29/avatar.svg"></a>

### Sponsors
Become a sponsor and get your logo on our README on Github with a link to your site :)
Become a sponsor and get your logo on our README on Github with a link to your site :)

<a href="https://opencollective.com/freshos/sponsor/0/website" target="_blank"><img src="https://opencollective.com/freshos/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/freshos/sponsor/1/website" target="_blank"><img src="https://opencollective.com/freshos/sponsor/1/avatar.svg"></a>
Expand Down
20 changes: 13 additions & 7 deletions Source/Arrow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public func <-- <T: RawRepresentable>(left: inout T, right: JSON?) {
/// Parses optional enums.
public func <-- <T: RawRepresentable>(left: inout T?, right: JSON?) {
var temp: T.RawValue? = nil
parseType(&temp, right:right)
parseType(&temp, right: right)
if let t = temp, let e = T.init(rawValue: t) {
left = e
}
Expand All @@ -119,7 +119,7 @@ public func <-- <T: RawRepresentable>(left: inout [T], right: JSON?) {
/// Parses Optional Array of enums.
public func <-- <T: RawRepresentable>(left: inout [T]?, right: JSON?) {
if let array = right?.data as? [T.RawValue] {
left = array.map { T.init(rawValue: $0) }.flatMap {$0}
left = array.map { T.init(rawValue: $0) }.compactMap {$0}
}
}

Expand All @@ -139,7 +139,7 @@ public func <-- <T: ArrowParsable>(left: inout T?, right: JSON?) {

/// Parses arrays of user defined custom types.
public func <-- <T: ArrowParsable>(left: inout [T], right: JSON?) {
setLeftIfIsResultNonNil(left:&left, right:right, function: <--)
setLeftIfIsResultNonNil(left: &left, right: right, function: <--)
}

/// Parses optional arrays of user defined custom types.
Expand Down Expand Up @@ -223,20 +223,20 @@ public func <-- (left: inout URL?, right: JSON?) {
str <-- right
let set = CharacterSet.urlQueryAllowed
if let escapedStr = str.addingPercentEncoding(withAllowedCharacters: set),
let url = URL(string:escapedStr) {
let url = URL(string: escapedStr) {
left = url
}
}

/// Parses arrays of plain swift types.
public func <-- <T>(left: inout [T], right: JSON?) {
setLeftIfIsResultNonNil(left:&left, right:right, function: <--)
setLeftIfIsResultNonNil(left: &left, right: right, function: <--)
}

/// Parses optional arrays of plain swift types.
public func <-- <T>(left: inout [T]?, right: JSON?) {
if let a = right?.data as? [Any] {
let tmp: [T] = a.flatMap { var t: T?; parseType(&t, right: JSON($0)); return t }
let tmp: [T] = a.compactMap { var t: T?; parseType(&t, right: JSON($0)); return t }
if tmp.count == a.count {
left = tmp
}
Expand Down Expand Up @@ -269,7 +269,13 @@ func parseType<T>(_ left: inout T?, right: JSON?) {
if let v: T = right?.data as? T {
left = v
} else if let s = right?.data as? String {
parseString(&left, string:s)
parseString(&left, string: s)
} else if T.self == Float.self {
// Sepcial case for Float that
// no longer works out of the box in Swift 4.1
if let v = right?.data as? Double, let l = Float(v) as? T {
left = l
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.0.0</string>
<string>4.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Loading

0 comments on commit 9f9ef35

Please sign in to comment.