UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 19 - error message -‘Trailing Closure Passed to parameter of type…’

Forums > 100 Days of SwiftUI

@CJ  

Hi

I am trying to complete the day 19 challenge (conversions app) and keep getting the following error message at the start of the 'Form' section (near the top of the code just under 'body' and 'NavigationView'-

"Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure.'

I was getting it also yesterday when I was extending the WeSplit app. I somehow managed to get rid of it though not sure how. At one point I was arbritrarily adding/deleting curly braces but that is not working here. I also notice sometimes it goes away as I type only to reappear when I finish. It also only seems to happen further down in the code, even when it is in the same format as the earlier code which is what is baffling me. I literally can add a header in exactly the same format that worked two lines before and yet, add it at the end of the next section and it brings up this error message. Just cannot make it out.

If anyone has had this error and can explain, it would be much appreciated!

2      

Please post some code that is giving you this error. It's very hard to help when we can't see what's wrong.

The two most probable causes of this are 1) unmatched braces, or 2) conflicting types with the same name. In this case, I doubt it's the latter.

The best way to find unmatched braces is to select all the code and use the ⌃I key combination.

2      

@CJ  

Thank you @roosterboy for your reply. I didn't post the code as I found it quite a procedure to do previously and it wouldn't embed like other people's and so got a bit put off. I've tried again below- It never embeds and is on a white background. If you are able to advise as to how to make it embed/ easier to read let me know and I will try again.

Anyway, the code should appear following the link. I should say, I was trying to get the visual side of the app sorted before properly creating the variables so am aware the app will not perform any function as yet. I don't think that is the issue but don't know.

Regarding matching braces, I tried to go through and could personally not see any errors but perhaps I am missing something. I am not sure how to access the key combination you show.

![conversion app] (https://www.dropbox.com/s/ivwhfaz3z1ozcqv/ConversionApp.png?raw=1)

Thanks

2      

Your link isn't working because you have a space between the ] and the (

![conversion app] (https://www.dropbox.com/s/ivwhfaz3z1ozcqv/ConversionApp.png?raw=1)
                 ^

When posted without the space, it works.

However...

When posting code to these forums, please post the code as text rather than an image. This makes it far easier to read (some of us have aging eyes!) and also makes it possible for other posters to copy/paste the code in order to test solutions and such without having to retype all your code from scratch.

To post your code as text, place three backticks ``` on the line before your code and three backticks ``` on the line after your code so that it will be formatted properly. You can also highlight an entire code block and click the </> button on the toolbar to wrap the block for you, athough it's usually better to put the backticks before you paste in your code.


Now, as to your particular problem, it lies on line 42: ($0, format: .number) should be Text($0, format: .number)

2      

@CJ  

Thank you @roosterboy - that is now working! I did have the error at other times as well but I deleted the code and it went away. Not sure if it was the same thing or not but it has definitely gone away for the moment. Sometimes you can't see what is in front of your eyes!

Many thanks again and for the advice re copying and pasting code - that is much easier than dropbox. I was wondering how everyone else was posting with such ease. Anyway, I will leave the incorrect bit of code here, in case anyone else comes across a similar issue and struggles with the earlier link:-

  Picker("litres" , selection: $litres)  {
            ForEach (litresArray, id: \.self) {
              ($0, format: .number)

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.