Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dynamically create two columns at runtime #52

Open
amsubhanTV opened this issue Jun 24, 2021 · 0 comments
Open

How to dynamically create two columns at runtime #52

amsubhanTV opened this issue Jun 24, 2021 · 0 comments

Comments

@amsubhanTV
Copy link

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"
        }
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant