is it possible to generate boiler plate form data entry views from templates/structs/classes in SwiftUI

Viewed 52

I need to create many data entry forms for simple structs/classes etc. I'd rather not be involved in the tedium of writing up the views manually.

Ideally I could just provide some "codable" struct/class and the view would could be generated automatically for me

As an example I have some models containing simple fields such as these

struct Person {
  let age: Int
  let firstName: String
  let lastName: String
}

struct Blah {
  let a: Int
  let b: String
  let c: Date
  let d: Float
}

etc. etc.

Any "magic" similar to "Codable" which could generate an appropriate SwiftUI view ?

for instance:

struct Person: SwiftUIView {
  ...
}
1 Answers

You can do that with Telosys ( https://www.telosys.org ) a code generator designed to reduce the programming workload by generating the "boiler plate" part of your application. It's a lightweight and pragmatic tool, easy to use.

It is based on "models" to define all your entities (just like the "struct" you mentioned) but writen with a specific (and quite simple) DSL ( see https://www.telosys.org/dsl-syntax.html )

Telosys can be used to generate any kind of programming languages. Currently it seems that there's no existing templates for SwiftUI, but it's quite simple to create your specific templates, they are based on the well known Velocity templating language ( https://velocity.apache.org/ ). Some templates examples are available on GitHub https://github.com/telosys-templates-v3.

For more information see also : https://modeling-languages.com/telosys-tools-the-concept-of-lightweight-model-for-code-generation/

Related