4

Is there a way to build eureka forms from a json/api response. So far i've been able to convert to json returned to an object. But having issues creating a for loop to generate the form.

form
+++ Section("API Returns")

for values in JSONObject{

    <<< TextRow() {
        $0.tag = values.key
        $0.title = values.name
        $0.value = values.value
    }
}
dankthreads
  • 313
  • 2
  • 16

2 Answers2

5

You need to indicate which Section the TextRow is going to be inserted to inside your loop.

let section = Section("API Returns")
form +++ section

for values in JSONObject{

    section <<< TextRow() {
        $0.tag = values.key
        $0.title = values.name
        $0.value = values.value
    }
}

You also use this assuming your "API Returns" section is the last section of your form.

for values in JSONObject {

    guard let section = self.form.last else {
        return
    }

    section <<< TextRow() {
        $0.tag = values.key
        $0.title = values.name
        $0.value = values.value
    }
}
koropok
  • 1,393
  • 13
  • 19
0

You can use this :

for values in JSONObject {

    guard let section = self.form.last else {
        return
    }

    section <<< TextRow() {
        $0.tag = values.key
        $0.title = values.name
        $0.value = values.value
    }
}
form
+++ section(){...}
Mohsen Fard
  • 597
  • 9
  • 22