Dynamic Classes and Variables

Hello All,

I need some help to achieve the following requirement.
I am receiving class metadata as REST api response(JSON) based on the received metadata i need to build class with variables. I have used @dynamicMemberLookup but it didn't gave me code intelligence. Please go through the below link for more details.

In general, the IDE cannot give you code completion for members that don't statically exist. The @dynamicMemberLookup type that you've got has dynamic keys, which may or may not exist and the IDE has no special knowledge of what those keys might be.

Do we have any other way/process to build model classes dynamically based on json response(metadata)?

Your requirements make no sense, if the properties are only known at runtime how to you want to use them (in a non generic way) at compile time? In other words if you want to write code like Person.name at compile time, the properties have to be known before.

If you want to support API changes which you know will come in the future, you can use Codable and Optionals. Then you could use a tool like the one you have linked to statically generate Types.

1 Like

Thank you @GrafHubertus.

Terms of Service

Privacy Policy

Cookie Policy