|
Hi all Hacking with Swift friend, I am a near complete beginner trying to build a questionnaire archive/collation tool for my profession. It's going pretty well overall! I am creating a list of navigation links in the present code (similar code will also be used for selectable list that generates views). Since there are many views I have used a ForEach to generate the navigationLink, however I need to organise them according to section headers. The ForEach requires .allCases and this means headers are produced for all navigation links instead of just a few. I can't work out the syntax to bind the correct header to each case from the enum. This is the enum (sorry for long/awful names):
Then the viewbuilder:
Finally, my attempt at assigning section headers to certain enum cases:
This is returning the error message "he compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions". I've been at this for hours and this is all I have come up with, any and all help is appreciated. |
|
I don't really understand what you are trying to do with this:
None of your And it's not quite clear to me if you want to show all the assessment types (because you are iterating At any rate, here's an attempt at what I think you are trying to do. Hopefully it's close enough that you can tweak it into shape and make it work.
Some notes:
|
|
Thankyou very much, that's made my code much clearer. Sorry you are right, I miscommunicated what I wanted. From how you said it, the first option is what I am trying to do:
I need all of ( The "0", "1", "2", "3" was me trying to check if it worked... very confusing given how I wrote it. These are the
Any further help and guidance you could provide would be much appreciated! I'll try to learn as much as I can from your changes! Thanks again. |
|
Thanks for the clarification. Try this:
Here's how it works:
And here's what it looks like in my simulator: Now, you should be aware that what this does is essentially:
If, instead, you want something like:
then that's a whole different kettle of fish and you would need to restructure your data in a more hierarchical fashion. |
|
OMG yes thankyou this works great. It's all coming together a lot better now thankyou. I think what you have given me there should work great. In regards to your final comment about how it's actually working:
Will it matter if I do one or the other? What is the fundamental difference between those two organisations if they are just generating navigation links? Thanks so much again. |
|
I think it mostly depends on how it's being presented in the app. Like SwiftUI might format items in a |
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.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.