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

Commit 220b6b0

Browse files
author
Harlan Kellaway
authored
Merge pull request #316 from hkellaway/release/2.0.0
Release/2.0.0
2 parents 2231423 + 609946e commit 220b6b0

28 files changed

+363
-216
lines changed

CHANGELOG.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
All notable changes to this project will be documented in this file.
33
`Gloss` adheres to [Semantic Versioning](http://semver.org/).
44

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

1818
---
1919

20+
## [2.0.0](https://github.com/hkellaway/Gloss/releases/tag/2.0.0)
21+
Released on 2017-12-06.
22+
23+
#### Added
24+
- De/Encoding for Double and [Double] [[PR #287](https://github.com/hkellaway/Gloss/pull/287)]
25+
26+
---
27+
2028
## [2.0.0-beta.2](https://github.com/hkellaway/Gloss/releases/tag/2.0.0-beta.2)
2129
Released on 2017-11-04.
2230

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

2634
---
2735

@@ -37,22 +45,22 @@ Released on 2017-09-27.
3745
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)
3846

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

4351
## [1.2.3](https://github.com/hkellaway/Gloss/releases/tag/1.2.3)
4452
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)
4553

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

4957
---
5058

5159
## [1.2.2](https://github.com/hkellaway/Gloss/releases/tag/1.2.2)
5260
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)
5361

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

5765
---
5866

Gloss.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Gloss"
3-
s.version = "2.0.0-beta.2"
3+
s.version = "2.0.0"
44
s.summary = "A shiny JSON parsing library in Swift"
55
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."
66
s.homepage = "https://github.com/hkellaway/Gloss"

Gloss.xcodeproj/project.pbxproj

Lines changed: 200 additions & 193 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
### Swift Version
2323

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

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

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

3232
```ruby
33-
pod 'Gloss', '2.0.0-beta.2'
33+
pod 'Gloss', '~> 2.0'
3434
```
3535

3636
### Installation with Carthage
@@ -497,6 +497,8 @@ The `<~~` operator is simply syntactic sugar for a set of `Decoder.decode` funct
497497
* Int64 array (`Decoder.decode(int64ArrayForKey:)`)
498498
* UInt64 types (`Decoder.decode(uint64ForKey:)`)
499499
* UInt64 array (`Decoder.decode(uint64ArrayForKey:)`)
500+
* Double types (`Decoder.decode(doubleForKey:)`)
501+
* Double array (`Decoder.decode(doubleArrayForKey:)`)
500502
* NSURL types (`Decoder.decode(urlForKey:)`)
501503
* NSURL arrays (`Decode.decode(urlArrayForKey:)`)
502504
* UUID types (`Decoder.decode(uuidForKey:)`)
@@ -523,6 +525,8 @@ The `~~>` operator is simply syntactic sugar for a set of `Encoder.encode` funct
523525
* Int64 arrays (`Encoder.encode(int64ArrayForKey:)`)
524526
* UInt64 types (`Encoder.encode(uint64ForKey:)`)
525527
* UInt64 arrays (`Encoder.encode(uint64ArrayForKey:)`)
528+
* Double types (`Encoder.encode(doubleForKey:)`)
529+
* Double arrays (`Encoder.encode(doubleArrayForKey:)`)
526530
* NSURL types (`Encoder.encode(urlForKey:)`)
527531
* UUID types (`Encoder.encode(uuidForKey:)`)
528532
* Decimal types (`Encoder.encode(decimalForKey:)`)
@@ -561,7 +565,7 @@ Check out Gloss in these cool places!
561565
#### Libraries
562566

563567
* [Alamofire-Gloss](https://github.com/spxrogers/Alamofire-Gloss)
564-
* [Moya-Gloss](https://github.com/spxrogers/Moya-Gloss)]
568+
* [Moya-Gloss](https://github.com/spxrogers/Moya-Gloss)
565569
* [Restofire-Gloss](https://github.com/Restofire/Restofire-Gloss)
566570

567571
#### Newsletters

Sources/Decoder.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,46 @@ public struct Decoder {
540540
}
541541
}
542542

543+
/**
544+
Decodes JSON to an Double.
545+
546+
- parameter key: Key used in JSON for decoded value.
547+
548+
- returns: Value decoded from JSON.
549+
*/
550+
public static func decode(doubleForKey key: String, keyPathDelimiter: String = GlossKeyPathDelimiter) -> (JSON) -> Double? {
551+
return {
552+
json in
553+
554+
if let number = json.valueForKeyPath(keyPath: key, withDelimiter: keyPathDelimiter) as? NSNumber {
555+
return number.doubleValue
556+
}
557+
558+
return nil
559+
}
560+
}
561+
562+
/**
563+
Decodes JSON to an Double array.
564+
565+
- parameter key: Key used in JSON for decoded value.
566+
567+
- returns: Value decoded from JSON.
568+
*/
569+
public static func decode(doubleArrayForKey key: String, keyPathDelimiter: String = GlossKeyPathDelimiter) -> (JSON) -> [Double]? {
570+
return {
571+
json in
572+
573+
if let numbers = json.valueForKeyPath(keyPath: key, withDelimiter: keyPathDelimiter) as? [NSNumber] {
574+
let doubles: [Double] = numbers.map { $0.doubleValue }
575+
576+
return doubles
577+
}
578+
579+
return nil
580+
}
581+
}
582+
543583
/**
544584
Decodes JSON to a Decimal.
545585

Sources/Encoder.swift

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,49 @@ public struct Encoder {
483483
return nil
484484
}
485485
}
486+
487+
/**
488+
Encodes a Double array to JSON.
489+
490+
- parameter key: Key used in JSON for decoded value.
491+
492+
- returns: JSON encoded from value.
493+
*/
494+
public static func encode(doubleForKey key: String) -> (Double?) -> JSON? {
495+
return {
496+
double in
497+
498+
if let double = double {
499+
return [key : NSNumber(value: double)]
500+
}
501+
502+
return nil
503+
}
504+
}
486505

487506
/**
488-
Encodes a Decimal to JSON.
507+
Encodes a Double array to JSON.
508+
509+
- parameter key: Key used in JSON for decoded value.
510+
511+
- returns: JSON encoded from value.
512+
*/
513+
public static func encode(doubleArrayForKey key: String) -> ([Double]?) -> JSON? {
514+
return {
515+
doubleArray in
516+
517+
if let doubleArray = doubleArray {
518+
let numbers: [NSNumber] = doubleArray.map { NSNumber(value: $0) }
519+
520+
return [key : numbers]
521+
}
522+
523+
return nil
524+
}
525+
}
526+
527+
/**
528+
Encodes a Double to JSON.
489529

490530
- parameter key: Key used in JSON for decoded value.
491531

Sources/Operators.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,30 @@ public func <~~ (key: String, json: JSON) -> [UUID]? {
266266
return Decoder.decode(uuidArrayForKey: key)(json)
267267
}
268268

269+
/**
270+
Convenience operator for decoding JSON to Double.
271+
272+
- parameter key: JSON key for value to decode.
273+
- parameter json: JSON.
274+
275+
- returns: Decoded value when successful, nil otherwise.
276+
*/
277+
public func <~~ (key: String, json: JSON) -> Double? {
278+
return Decoder.decode(doubleForKey: key)(json)
279+
}
280+
281+
/**
282+
Convenience operator for decoding JSON to Double array.
283+
284+
- parameter key: JSON key for value to decode.
285+
- parameter json: JSON.
286+
287+
- returns: Decoded value when successful, nil otherwise.
288+
*/
289+
public func <~~ (key: String, json: JSON) -> [Double]? {
290+
return Decoder.decode(doubleArrayForKey: key)(json)
291+
}
292+
269293
/**
270294
Convenience operator for decoding JSON to Decimal.
271295

@@ -522,6 +546,30 @@ public func ~~> (key: String, property: UUID?) -> JSON? {
522546
return Encoder.encode(uuidForKey: key)(property)
523547
}
524548

549+
/**
550+
Convenience operator for encoding a Double to JSON.
551+
552+
- parameter key: JSON key for value to encode.
553+
- parameter property: Object to encode to JSON.
554+
555+
- returns: JSON when successful, nil otherwise.
556+
*/
557+
public func ~~> (key: String, property: Double?) -> JSON? {
558+
return Encoder.encode(doubleForKey: key)(property)
559+
}
560+
561+
/**
562+
Convenience operator for encoding a Double array to JSON.
563+
564+
- parameter key: JSON key for value to encode.
565+
- parameter property: Object to encode to JSON.
566+
567+
- returns: JSON when successful, nil otherwise.
568+
*/
569+
public func ~~> (key: String, property: [Double]?) -> JSON? {
570+
return Encoder.encode(doubleArrayForKey: key)(property)
571+
}
572+
525573
/**
526574
Convenience operator for encoding a Decimal to JSON.
527575

File renamed without changes.

Tests/GlossTests/DecoderTests.swift renamed to Tests/DecoderTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,19 @@ class DecoderTests: XCTestCase {
199199
}
200200

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

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

207207
func testDecodeDoubleArray() {
208-
let result: [Double]? = Decoder.decode(key: "doubleArray")(testJSON!)
208+
let result: [Double]? = Decoder.decode(doubleArrayForKey: "doubleArray")(testJSON!)
209209
let element1: Double = result![0]
210210
let element2: Double = result![1]
211211
let element3: Double = result![2]
212212

213213
XCTAssertTrue((element1 == 4.0), "Decode Double array should return correct value")
214-
XCTAssertTrue((element2 == 5.0), "Decode Double array should return correct value")
214+
XCTAssertTrue((element2 == 5), "Decode Double array should return correct value")
215215
XCTAssertTrue((element3 == 6.0), "Decode Double array should return correct value")
216216
}
217217

Tests/GlossTests/EncoderTests.swift renamed to Tests/EncoderTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ class EncoderTests: XCTestCase {
118118

119119
func testEncodeDouble() {
120120
let double: Double? = 4.0
121-
let result: JSON? = Encoder.encode(key: "double")(double)
121+
let result: JSON? = Encoder.encode(doubleForKey: "double")(double)
122122

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

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

130130
XCTAssertTrue((result!["doubleArray"] as! [Double] == [4.0, 5.0, 6.0]), "Encode Double array should return correct value")
131131
}

0 commit comments

Comments
 (0)