carson-katri / swift-request

Declarative HTTP networking, designed for SwiftUI
MIT License
730 stars 41 forks source link

Improved `Json` Implementation #9

Closed carson-katri closed 5 years ago

carson-katri commented 5 years ago

Json is now more dynamic to support better reading of values, and optionals.

codecov-io commented 5 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (dev@8aa6735). Click here to learn what that means. The diff coverage is 68.58%.

Impacted file tree graph

@@          Coverage Diff          @@
##             dev      #9   +/-   ##
=====================================
  Coverage       ?   65.2%           
=====================================
  Files          ?      21           
  Lines          ?     526           
  Branches       ?       0           
=====================================
  Hits           ?     343           
  Misses         ?     183           
  Partials       ?       0
Impacted Files Coverage Δ
Sources/Request/Request/Extra/RequestChain.swift 80.76% <ø> (ø)
...es/Request/SwiftUI/RequestImage/RequestImage.swift 0% <0%> (ø)
Sources/Json/JsonBuilder.swift 0% <0%> (ø)
Tests/RequestTests/RequestTests.swift 94.26% <100%> (ø)
Sources/Json/JsonSubscript.swift 100% <100%> (ø)
Sources/Json/Literals.swift 25% <25%> (ø)
Sources/Request/Request/Request.swift 78.31% <41.66%> (ø)
Sources/Json/Json.swift 75.34% <75.34%> (ø)
Tests/RequestTests/JsonTests.swift 82.22% <82.22%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8aa6735...f336e50. Read the comment docs.

carson-katri commented 5 years ago

JsonBuilder was removed in favor of ExpressibleByDictionaryLiteral, as well as other literals:

let json: Json = ["key": "value"]
let json: Json = ["Hello", "World"]
let json: Json = "Hello, world!"
let json: Json = 5
let json: Json = 9.41

@dynamicMemberLookup allows subscripting to be more expressive:

// Instead of:
myJson["key"][0]["key2"]
// We can do:
myJson.key[0].key2

This is safer than the subscript, however both are available. You can also use the lookup to set values:

myJson.key[0].key2 = 5
myJson.key = ["Hello", "World"]