SwiftyJSON map for array

let json = JSON(response.result.value!)

let things = json.array.map { jsonThing in          
   Thing()                    
}!

json.arrayreturns an array of one hundred JSONs. After the call, mapI get one Thing.

Why don't I have a new Things array ?

+4
source share
2 answers

SwiftyJSON has two types of getters: optional and optional.

Optional getters have the syntax of the name "... Value".

Additionally:

json.array

non-optional:

json.arrayValue

: , . , if let ( ) : , ..

+5

json.array [JSON]?, [JSON]

, .map Optional<[JSON]>, Array<JSON>, .

:

json.array?.map ...

+2

Source: https://habr.com/ru/post/1613369/


All Articles