Trouble with Menu 05 Challenge

Hi - I am struggling to get a working solution to the challenge. Conceptually, it should be simple. Use the List over an array. My problem is figuring out how to keep adding elements into the array, randomly, from the list (array) of original words. Can someone share their solution? Thanks.

Welcome to the community!

The challenges have included solutions from Chris! At the beginning of module

Thank so much for your quick reply. I agree, that solutions to the lecture are in the resources, but, I have looked, and looked, and looked - I can’t find the solution for this specific challenge… If it’s there, I’d appreciate a link or screen shot on how to find it - otherwise, a hint at the solution. Thanks again.

1 Like

I second that. I can´t seem to find the solution too :confused:

Oh no! Let me double check it’s linked

@DerLandarzt welcome to the community! Thanks for also letting us know you’re having the same issue

Thanks for the heads up! I’m putting up the solution in a sec… Will follow up here when it’s in dropbox!

@DerLandarzt @piratemc74
The challenge solution is in the dropbox Lesson 5 folder now. Thank you for the heads up everyone!

1 Like

Wow, that was fast! Thank you very much!

Thanks so much… couldn’t get the “id” for the list item… I tried creating a new Struct, but, was having issues instantiating a new instance of the Struct, and putting the random word over it, then, using List on the struct… Using the inherent “id” makes sense…

Just checking, but was I meant to know all the options used in the solution before the challange? maybe (that’s a strong maybe) I may have figured some stuff solo, but im not sure if the aim was to use stuff ive learnt, or discover new stuff solo. cause I strongly feel some stuff wasn’t covered (I did try and fail many times before finding solutions but I couldn’t get the answers to list or randomly generate)

@isaaccrown

Welcome to the community.

As with any challenge the intention is to stretch your knowledge and in some cases you may need to do a little research.

The List should show the contents of the array that you are adding elements to from the other array you would have declared that had the 5 strings.

Getting a random element from an array can be done in a number of ways. Search on Google for “Swift get a random element from an array” and you will get many answers.

Got errors about not being mutable no matter what solution I did. Had to resort to making mine look identical to yours. No amount of researched on the topic helped. My approach had been with functions and structs. Tried abandoning the struct and continuing with function call for the button. Could not get that to work. Had to make my code look just like yours with append directly in the button. I found the full structure and what should have worked but ultimately really frustrating challenge that I don’t feel rewarded for my work on. Hope future challenges are better.

Inside a struct a variable is only mutable if it is declared as a @State property. @State is a special property wrapper that allows variables inside a SwiftUI struct to be changed (mutable means “liable to change.”).

1 Like

Thanks Chris. I had @State when I got the errors and basically gave up on the struct I had created before giving up and making my code match the solution provided. Going back now, I changed the code back to what I had thought would originally work and it’s working! Not sure what happened and now I can’t replicate the error now.