Search code examples
iosswifteureka-forms

Dynamically generate Eureka Form Rows


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
    }
}

Solution

  • 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
        }
    }