Skip to content

How to dynamically create two columns at runtime #52

@amsubhanTV

Description

@amsubhanTV

I am creating a form builder and I want to create a form with two columns based on given JSON data. The issue is that my method decides on runtime which form item (like TextRow, NameRow etc) is to be rendered so I need to provide some base class/interface to SplitView like in the following way:

SplitRow<BaseRow,BaseRow>(){
   $0.rowLeft = getFormField(fieldToRender: "Text Area") as? TextAreaRow // getFormField decides on runtime which type of field to render i.e TextRow and returns BaseRow type.
   $0.rowRight = getFormField(fieldToRender: "Text  Row") as? TextRow
}

But the above code gives the following error:-
Type 'BaseRow' does not conform to protocol 'RowType'

I want that somehow I can give a base class to Split row so it can infer class (form item) at runtime as Eureka does, if I pass BaseRow to Eurekas <<< operator it dynamically renders the field base on given sub class. Following is Eureka's example that accepts BaseRow class and renders given form filed, TextRow or PickerInputRow or any other class:

form.last! <<< getFormField(fieldToRender: "Text Field")

For refrence i have added getFormField() method:-

func getFormField(fieldToRender: String) -> BaseRow {
    if fieldToRender == "Text Area" {
        return  TextAreaRow(){
            $0.title = "Title"
            $0.value = "Value"
        }
    }else{
            return  TextRow() {
            $0.title = "Title"
            $0.value = "Value"
        }
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions