rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
907 stars 95 forks source link

How to pass parameters to a make func #68

Closed razvanrujoiu closed 2 years ago

razvanrujoiu commented 2 years ago

I have the following scenario: i want to pass parameters to a function that returns a view:

@ViewBuilder
    private func makeMailComposeVC(recepients: [String], capturedImage: UIImage, completion: @escaping Action) -> some View {
        MailComposeViewController(toRecipients: recepients, capturedImage: capturedImage, didFinish: completion)
    }

but here it says: "No exact matches in call to initalizer"

@Route(.modal) var mailCompose = makeMailComposeVC

savage7 commented 2 years ago

Like this: router.route(to: \. mailCompose, (recepients, capturedImage, ...))

Or better create a model for this and pass it as param.

razvanrujoiu commented 2 years ago

@savage7 i understand, but if i put parameters in the function makeMailComposeVC header then at @Route declaration (@Route(.modal) var mailCompose = makeMailComposeVC) it would yell at me that "No exact matches in call to initalizer" How do i declare the parameters of the function there?

savage7 commented 2 years ago

roughly like this: private func makeMailComposeVC(param:(recepients: [String], capturedImage: UIImage, completion: @escaping Action)) -> some View {

razvanrujoiu commented 2 years ago

That is what i needed, now it works like a charm, thank you @savage7