let json = JSON(response.result.value!)
let things = json.array.map { jsonThing in
Thing()
}!
json.array
returns an array of one hundred JSON
s. After the call to map
, I end up with a single Thing
.
Why don't I have a new array of Thing
s?
SwiftyJSON has two kinds of getters: optional and non-optional.
The non-optional getters have the "...Value" name syntax.
Optional:
json.array
Non-optional:
json.arrayValue
Be careful, though: if you're using the non-optional getters with a nil value it will crash. If the value can be nil it's better to use the optional getter and safely unwrap with if let
(optional binding) or any other known technique: optional chaining, nil coalescing, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With