Search code examples
swiftalamofireeureka-forms

Create PushRow in existing section and pass value in runtime


How to create PushRow dynamically and pass value from alamofire function. This is my alamofire function and i want to create pushRow with the alamofire response

nw.getJsonData(api: Api.assetCategory) { (response, error) in

}

func createPushRow(_ title: String, _ placeholder: String, _ options: [String]) {
    form +++ Section("Choose " + title)
        <<< PushRow<String>() { row in
            row.title = title.lowercased()
            row.selectorTitle = "Pick " + title.lowercased()
            row.options = options
    }
}

Solution

  • You can either just change the options of the PushRow like this:

    (form.rowBy(tag: "<tagOfRow>") as? PushRow<String>)?.options = ["💁🏻", "🍐", "👦🏼"]
    

    Or you can set the optionsProvider in the row initializer to lazy and get the options each time the PushRow is selected.

    form +++ Section("Choose " + title)
        <<< PushRow<String>() { row in
                row.optionsProvider = .lazy({ (formViewController, completion) in
                    // Call Alamofire to get options
                    // options = ...
                    completion(options)
                })
                // .... other set up
            }