|
I have this code to access to JSON that is online. It works well:
I would like to do the same dynamically. I mean that the user can choose in a textField if he wants to pick up the information name, mail... I tried many things. For instance: var hePicks = textField1.stringValue print (users![0].hePicks) It seems that I cannot put a var there!. If I print print (users![0]) the information is there. How can I choose dynamically one of the fields? |
|
|
|
Ok. Then, how do you make that dynamic?. Please, how would you do it in my example? I suppose the question is how to create a var/let inside the struct. Dynamically, create the var with what the user writes in the text field |
|
It depends on your UI. You do not use the "load" to change as in your code. I have done a little SwiftUI just to show, as I am quicker in that. I changed your
then this in ContentView
|
|
I think I did no explain well. I simplified the case to ask the question here, but there are many options. Not only name an mail. I cannot solve the problem with a conditional if else. The user writes in a text field what he wants. With that information I have to create the var/let inside the struct |
|
If I get this right You want the user to enter in a I do not think this is possible! You will have to provide the list of the fields that the user can pick then use that information. Which I did in the You can change the
and the Picker to this
then change if statement
As the above code show by giving them what to choose then you can change on their choice. See Below with TextField
|
|
Ok. I understand. To write all the options in my real case make things really complicated. I suppose that I will have to begin offering only a few things to choose to the user. Thank you! |
SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
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.