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

Iterate Static Arrays #1158

Open
davidscheutz opened this issue Apr 2, 2023 · 1 comment
Open

Iterate Static Arrays #1158

davidscheutz opened this issue Apr 2, 2023 · 1 comment

Comments

@davidscheutz
Copy link

davidscheutz commented Apr 2, 2023

I have this idea to simplify my code by generating code to constructor inject dependencies specified within my project.

The essential part of my code:

protocol MyProtocol {
     static var dependencies: [AnyClass.Type] { get }
}
final class MyClass: MyProtocol {
     static let dependencies: [AnyClass.Type] = [ApiClient.self]
}

What I would like to generate:

class MyClassBase {
     let apiClient: ApiClient

     init(apiClient: ApiClient) {
           self. apiClient = apiClient
     }
}

Usage

final class MyClass: MyClassBase, MyProtocol { ... }

Where I'm stuck
How do I read the values from the dependencies array?

I was trying something like this

{% for type in types.based.MyProtocol %}
class {{ type.name }}Base {

    {% for dependencyType in type.dependencies %}
    let {{ dependencyType.name|lowerFirst }}: {{ dependencyType.name }}
    {% endfor %}

    // ...

{% endfor %}

but without any result.

Happy to make that contribution myself if others find it valuable too.
I'm new to this project so if someone could point me in the right direction, that would be great.

Appreciate any ideas and support 🙌🏻

@davidscheutz davidscheutz changed the title Iterate Static Immutable Arrays Iterate Static Arrays Apr 3, 2023
@krzysztofzablocki
Copy link
Owner

you'd need to split defaultValue, dependencies is not an array in AST model, it's just a variable of array type

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

2 participants