Alternate to code generation


Presently there is a need to build a concrete swift class / struct based on the structure of a given JSON.

The approach presently considered is code generation (and add it in Xcode > Build Phase)

Is there an alternate / better way to do this without code generation and still maintaining strongly typed parameters.

I was thinking may be some of the new features might help to solve this problem ... but am not sure.

Any help would be much appreciated. Thanks


1 Like

thanks a lot!, this is pretty cool

At my work place they have proposed a solution for GraphQL and they have written their custom script to generate the classes. I am not sure if this is the approach to have it Xcode > Build Phases to generate these files.


  • Is it better to use a tool to generate the classes outside of the project and just use the generated classes in the project (or is it better to have it in Xcode > Build Phases)?
  • Is there a completely different approach that is possible using result builders or any of the other swift features to make it strongly type by accepting a JSON?

It certainly would be useful to have a script in the build phases that generates the swift types from the JSON data.

Result builders have nothing to do with code generation.


Thanks a lot for the clarification

Terms of Service

Privacy Policy

Cookie Policy