Post

Replies

Boosts

Views

Created

Basic API into app to variables
Hi All - I'm a new developer and have been having the hardest time attempting to get an API into my app. I created a blank app (pasted in) to essentially isolate all other possible things that could be affecting this, and am attempting to set each value in this test API I made to a variable in my app. I've spent hours watching YouTube videos and reading forums on here as well as on Reddit and nothing seems to help. I was hoping someone who understood this better than I do would be able to explain to me how this should work. Here's the very basic test app... //Here's just my test app... import swiftUI import Foundation // // // The API is a URL which contains the following values. // // [{"value1":"12","value2":"15","value3":"19"}] // //This isn't going to be the final API I'm using, I just needed something easy to test with. //I would like to assign the values from each of the values in the API to the variables below. This is the stage in the process where I seem to fall flat :( var var1 = // First Value from API var var2 = // Second Value from API var var3 = // Third Value from API struct ContentView: View { var body: some View { VStack{ Text(var1) Text(var2) Text(var3) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } Any help would be appreciated - I'm 100% lost. I just started learning Swift and SwiftUI this fall and never had to deal with APIs before now. I'm used to using them in GoogleAppsScript and JS but I, for some reason, can't figure out how to use them on Swift. Thank you to anyone who responds. Stay safe and healthy! -James
8
0
1.5k
Jan ’22