Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #316 from hkellaway/release/2.0.0
Browse files Browse the repository at this point in the history
Release/2.0.0
  • Loading branch information
Harlan Kellaway authored Dec 6, 2017
2 parents 2231423 + 609946e commit 220b6b0
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 216 deletions.
18 changes: 13 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
All notable changes to this project will be documented in this file.
`Gloss` adheres to [Semantic Versioning](http://semver.org/).

- `2.0.x` Releases - [2.0.0-beta.1](#200-beta1) | [2.0.0-beta.2](#200-beta2)
- `2.0.x` Releases - [2.0.0-beta.1](#200-beta1) | [2.0.0-beta.2](#200-beta2) | [2.0.0](#200)
- `1.2.x` Releases - [1.2.0](#120) | [1.2.1](#121) | [1.2.2](#122) | [1.2.3](#123) | [1.2.4](#124)
- `1.1.x` Releases - [1.1.0](#110) | [1.1.1](#111)
- `1.0.x` Releases - [1.0.0](#100)
Expand All @@ -17,11 +17,19 @@ All notable changes to this project will be documented in this file.

---

## [2.0.0](https://github.com/hkellaway/Gloss/releases/tag/2.0.0)
Released on 2017-12-06.

#### Added
- De/Encoding for Double and [Double] [[PR #287](https://github.com/hkellaway/Gloss/pull/287)]

---

## [2.0.0-beta.2](https://github.com/hkellaway/Gloss/releases/tag/2.0.0-beta.2)
Released on 2017-11-04.

#### Updated
- Naming of `Decodable` and `Encodable` protocols to `JSONDecodable` and `JSONEncodable` [PR #311](https://github.com/hkellaway/Gloss/pull/311)
- Naming of `Decodable` and `Encodable` protocols to `JSONDecodable` and `JSONEncodable` [[PR #311](https://github.com/hkellaway/Gloss/pull/311)]

---

Expand All @@ -37,22 +45,22 @@ Released on 2017-09-27.
Released on 2017-03-30. All issues associated with this milestone can be found using this [filter](https://github.com/hkellaway/Gloss/issues?utf8=%E2%9C%93&q=milestone%3A1.2.4)

#### Added
- Ability to inject logger used by Decoder [Issue #282](https://github.com/hkellaway/Gloss/pull/282)
- Ability to inject logger used by Decoder [[Issue #282](https://github.com/hkellaway/Gloss/pull/282)]
---

## [1.2.3](https://github.com/hkellaway/Gloss/releases/tag/1.2.3)
Released on 2017-03-29. All issues associated with this milestone can be found using this [filter](https://github.com/hkellaway/Gloss/issues?utf8=%E2%9C%93&q=milestone%3A1.2.3)

#### Fixed
- Logging when a value cannot be found despite the value being null [Issue #279](https://github.com/hkellaway/Gloss/issues/279)
- Logging when a value cannot be found despite the value being null [[Issue #279](https://github.com/hkellaway/Gloss/issues/279)]

---

## [1.2.2](https://github.com/hkellaway/Gloss/releases/tag/1.2.2)
Released on 2017-03-28. All issues associated with this milestone can be found using this [filter](https://github.com/hkellaway/Gloss/issues?utf8=%E2%9C%93&q=milestone%3A1.2.2)

#### Added
- Logging for when a value is found but cannot be decoded [PR #277](https://github.com/hkellaway/Gloss/pull/277)
- Logging for when a value is found but cannot be decoded [[PR #277](https://github.com/hkellaway/Gloss/pull/277)]

---

Expand Down
2 changes: 1 addition & 1 deletion Gloss.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Gloss"
s.version = "2.0.0-beta.2"
s.version = "2.0.0"
s.summary = "A shiny JSON parsing library in Swift"
s.description = "A shiny JSON parsing library in Swift. Features include mapping JSON to objects, mapping objects to JSON, handling of nested objects and custom transformations."
s.homepage = "https://github.com/hkellaway/Gloss"
Expand Down
393 changes: 200 additions & 193 deletions Gloss.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

### Swift Version

The Gloss source currently available via CocoaPods and Carthage is compatible with Swift 4.0 (version `2.0.0-beta.x`).
The Gloss source currently available via CocoaPods and Carthage is compatible with Swift 4.0.

To use the lastest version compatible with Swift 3.0, utilize version `1.2.x`.

Expand All @@ -30,7 +30,7 @@ Swift 2.x is no longer supported.
### Installation with CocoaPods

```ruby
pod 'Gloss', '2.0.0-beta.2'
pod 'Gloss', '~> 2.0'
```

### Installation with Carthage
Expand Down Expand Up @@ -497,6 +497,8 @@ The `<~~` operator is simply syntactic sugar for a set of `Decoder.decode` funct
* Int64 array (`Decoder.decode(int64ArrayForKey:)`)
* UInt64 types (`Decoder.decode(uint64ForKey:)`)
* UInt64 array (`Decoder.decode(uint64ArrayForKey:)`)
* Double types (`Decoder.decode(doubleForKey:)`)
* Double array (`Decoder.decode(doubleArrayForKey:)`)
* NSURL types (`Decoder.decode(urlForKey:)`)
* NSURL arrays (`Decode.decode(urlArrayForKey:)`)
* UUID types (`Decoder.decode(uuidForKey:)`)
Expand All @@ -523,6 +525,8 @@ The `~~>` operator is simply syntactic sugar for a set of `Encoder.encode` funct
* Int64 arrays (`Encoder.encode(int64ArrayForKey:)`)
* UInt64 types (`Encoder.encode(uint64ForKey:)`)
* UInt64 arrays (`Encoder.encode(uint64ArrayForKey:)`)
* Double types (`Encoder.encode(doubleForKey:)`)
* Double arrays (`Encoder.encode(doubleArrayForKey:)`)
* NSURL types (`Encoder.encode(urlForKey:)`)
* UUID types (`Encoder.encode(uuidForKey:)`)
* Decimal types (`Encoder.encode(decimalForKey:)`)
Expand Down Expand Up @@ -561,7 +565,7 @@ Check out Gloss in these cool places!
#### Libraries

* [Alamofire-Gloss](https://github.com/spxrogers/Alamofire-Gloss)
* [Moya-Gloss](https://github.com/spxrogers/Moya-Gloss)]
* [Moya-Gloss](https://github.com/spxrogers/Moya-Gloss)
* [Restofire-Gloss](https://github.com/Restofire/Restofire-Gloss)

#### Newsletters
Expand Down
40 changes: 40 additions & 0 deletions Sources/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,46 @@ public struct Decoder {
}
}

/**
Decodes JSON to an Double.
- parameter key: Key used in JSON for decoded value.
- returns: Value decoded from JSON.
*/
public static func decode(doubleForKey key: String, keyPathDelimiter: String = GlossKeyPathDelimiter) -> (JSON) -> Double? {
return {
json in

if let number = json.valueForKeyPath(keyPath: key, withDelimiter: keyPathDelimiter) as? NSNumber {
return number.doubleValue
}

return nil
}
}

/**
Decodes JSON to an Double array.
- parameter key: Key used in JSON for decoded value.
- returns: Value decoded from JSON.
*/
public static func decode(doubleArrayForKey key: String, keyPathDelimiter: String = GlossKeyPathDelimiter) -> (JSON) -> [Double]? {
return {
json in

if let numbers = json.valueForKeyPath(keyPath: key, withDelimiter: keyPathDelimiter) as? [NSNumber] {
let doubles: [Double] = numbers.map { $0.doubleValue }

return doubles
}

return nil
}
}

/**
Decodes JSON to a Decimal.
Expand Down
42 changes: 41 additions & 1 deletion Sources/Encoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,49 @@ public struct Encoder {
return nil
}
}

/**
Encodes a Double array to JSON.
- parameter key: Key used in JSON for decoded value.
- returns: JSON encoded from value.
*/
public static func encode(doubleForKey key: String) -> (Double?) -> JSON? {
return {
double in

if let double = double {
return [key : NSNumber(value: double)]
}

return nil
}
}

/**
Encodes a Decimal to JSON.
Encodes a Double array to JSON.
- parameter key: Key used in JSON for decoded value.
- returns: JSON encoded from value.
*/
public static func encode(doubleArrayForKey key: String) -> ([Double]?) -> JSON? {
return {
doubleArray in

if let doubleArray = doubleArray {
let numbers: [NSNumber] = doubleArray.map { NSNumber(value: $0) }

return [key : numbers]
}

return nil
}
}

/**
Encodes a Double to JSON.
- parameter key: Key used in JSON for decoded value.
Expand Down
48 changes: 48 additions & 0 deletions Sources/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,30 @@ public func <~~ (key: String, json: JSON) -> [UUID]? {
return Decoder.decode(uuidArrayForKey: key)(json)
}

/**
Convenience operator for decoding JSON to Double.
- parameter key: JSON key for value to decode.
- parameter json: JSON.
- returns: Decoded value when successful, nil otherwise.
*/
public func <~~ (key: String, json: JSON) -> Double? {
return Decoder.decode(doubleForKey: key)(json)
}

/**
Convenience operator for decoding JSON to Double array.
- parameter key: JSON key for value to decode.
- parameter json: JSON.
- returns: Decoded value when successful, nil otherwise.
*/
public func <~~ (key: String, json: JSON) -> [Double]? {
return Decoder.decode(doubleArrayForKey: key)(json)
}

/**
Convenience operator for decoding JSON to Decimal.
Expand Down Expand Up @@ -522,6 +546,30 @@ public func ~~> (key: String, property: UUID?) -> JSON? {
return Encoder.encode(uuidForKey: key)(property)
}

/**
Convenience operator for encoding a Double to JSON.
- parameter key: JSON key for value to encode.
- parameter property: Object to encode to JSON.
- returns: JSON when successful, nil otherwise.
*/
public func ~~> (key: String, property: Double?) -> JSON? {
return Encoder.encode(doubleForKey: key)(property)
}

/**
Convenience operator for encoding a Double array to JSON.
- parameter key: JSON key for value to encode.
- parameter property: Object to encode to JSON.
- returns: JSON when successful, nil otherwise.
*/
public func ~~> (key: String, property: [Double]?) -> JSON? {
return Encoder.encode(doubleArrayForKey: key)(property)
}

/**
Convenience operator for encoding a Decimal to JSON.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,19 @@ class DecoderTests: XCTestCase {
}

func testDecodeDouble() {
let result: Double? = Decoder.decode(key: "double")(testJSON!)
let result: Double? = Decoder.decode(doubleForKey: "double")(testJSON!)

XCTAssertTrue((result == 6.0), "Decode Double should return correct value")
}

func testDecodeDoubleArray() {
let result: [Double]? = Decoder.decode(key: "doubleArray")(testJSON!)
let result: [Double]? = Decoder.decode(doubleArrayForKey: "doubleArray")(testJSON!)
let element1: Double = result![0]
let element2: Double = result![1]
let element3: Double = result![2]

XCTAssertTrue((element1 == 4.0), "Decode Double array should return correct value")
XCTAssertTrue((element2 == 5.0), "Decode Double array should return correct value")
XCTAssertTrue((element2 == 5), "Decode Double array should return correct value")
XCTAssertTrue((element3 == 6.0), "Decode Double array should return correct value")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ class EncoderTests: XCTestCase {

func testEncodeDouble() {
let double: Double? = 4.0
let result: JSON? = Encoder.encode(key: "double")(double)
let result: JSON? = Encoder.encode(doubleForKey: "double")(double)

XCTAssertTrue((result!["double"] as! Double == 4.0), "Encode Double should return correct value")
}

func testEncodeDoubleArray() {
let doubleArray: [Double]? = [4.0, 5.0, 6.0]
let result: JSON? = Encoder.encode(key: "doubleArray")(doubleArray)
let doubleArray: [Double]? = [4.0, 5, 6.0]
let result: JSON? = Encoder.encode(doubleArrayForKey: "doubleArray")(doubleArray)

XCTAssertTrue((result!["doubleArray"] as! [Double] == [4.0, 5.0, 6.0]), "Encode Double array should return correct value")
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ class OperatorTests: XCTestCase {

func testDecodeOperatorGenericReturnsDecoderDecodeForDouble() {
let resultDouble: Double? = "double" <~~ testJSON!
let decoderResultDouble: Double? = Decoder.decode(key: "double")(testJSON!)
let decoderResultDouble: Double? = Decoder.decode(doubleForKey: "double")(testJSON!)

XCTAssertTrue((resultDouble == decoderResultDouble), "<~~ for generic value should return same as Decoder.decode for Double")
}

func testDecodeOperatorGenericReturnsDecoderDecodeForDoubleArray() {
let resultDoubleArray: [Double]? = "doubleArray" <~~ testJSON!
let decoderResultDoubleArray: [Double]? = Decoder.decode(key: "doubleArray")(testJSON!)
let decoderResultDoubleArray: [Double]? = Decoder.decode(doubleArrayForKey: "doubleArray")(testJSON!)

XCTAssertTrue((resultDoubleArray! == decoderResultDoubleArray!), "<~~ for generic value should return same as Decoder.decode for Double array")
}
Expand Down Expand Up @@ -337,15 +337,15 @@ class OperatorTests: XCTestCase {
func testEncodeOperatorGenericReturnsEncoderEncodeForDouble() {
let double: Double? = 1.0
let resultDouble: JSON? = "double" ~~> double
let encoderResultDouble: JSON? = Encoder.encode(key: "double")(double)
let encoderResultDouble: JSON? = Encoder.encode(doubleForKey: "double")(double)

XCTAssertTrue(((resultDouble!["double"] as! Double) == (encoderResultDouble!["double"] as! Double)), "~~> for generic value should return same as Encoder.encode for Double")
}

func testEncodeOperatorGenericReturnsEncoderEncodeForDoubleArray() {
let doubleArray: [Double]? = [1.0, 2.0, 3.0]
let doubleArray: [Double]? = [1.0, 2, 3.0]
let resultDoubleArray: JSON? = "doubleArray" ~~> doubleArray
let encoderResultDoubleArray: JSON? = Encoder.encode(key: "doubleArray")(doubleArray)
let encoderResultDoubleArray: JSON? = Encoder.encode(doubleArrayForKey: "doubleArray")(doubleArray)

XCTAssertTrue(((resultDoubleArray!["doubleArray"] as! [Double]) == (encoderResultDoubleArray!["doubleArray"] as! [Double])), "~~> for generic value should return same as Encoder.encode for Double array")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"float" : 2.0,
"floatArray" : [1.0, 2.0, 3.0],
"double" : 6.0,
"doubleArray" : [4.0, 5.0, 6.0],
"doubleArray" : [4.0, 5, 6.0],
"dictionary" : {
"otherModel" : {
"id" : 789,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ extension TestModel {
"float" : Float(2.0),
"floatArray" : [Float(1.0), Float(2.0), Float(3.0)],
"double" : Double(6.0),
"doubleArray" : [Double(4.0), Double(5.0), Double(6.0)],
"doubleArray" : [Double(4.0), Double(5), Double(6.0)],
"dictionary" : [
"otherModel" : [
"id" : 789,
Expand Down

0 comments on commit 220b6b0

Please sign in to comment.