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

Expose initializer with optional parameters in generated Swift code #309

Open
tbogosia opened this issue Jul 31, 2023 · 0 comments
Open

Comments

@tbogosia
Copy link

In version 9.1.0 of Typewriter, it looks like a convenience is generated to create a tracking event with optional values:

    func with(
        parameter1: String?? = nil,
        parameter2: String?? = nil
    ) -> MyEvent {
        return MyEvent(
            parameter1: parameter1 ?? self. parameter2,
            parameter2: parameter2 ?? self. parameter2
        )
    }

It would be great to have something like this, but more of a static function with default values for optional properties, like:

    static func with(
        parameter1: String? = nil,
        parameter2: String? = nil
    ) -> MyEvent {
        return MyEvent(
            parameter1: parameter1,
            parameter2: parameter2
        )
    }

This way at the call site I could use MyEvent.with(parameter1: "value") rather than need to pass in nil for all of the properties I know aren't relevant. I could see a case made for wanting to bring attention to all properties at the call site, but at least in my app this would save a lot of unnecessary noise.

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