Post

Replies

Boosts

Views

Activity

Passing Data between Views
Hi all, I am trying to create a weather app but i am struggling with passing data between views. I have a lat & lon variable which by default is set to the current location of the user. When the user selects to change location view they are able to select a new location, In which i need to be able to change the Lat & lon variable to the selected variables. Could someone please help me with the most efficient way of doing this. Thank you in advance
2
0
281
Dec ’20
Sending variable between views & Classes
Hi All, First post here. I am new to SwiftUi & app development and im struggling with passing data between views & classes. I have been following a tutorial but i want to add further functionality as a good way for learning. I have a weatherView with the following code struct WeatherView: View { @ObservedObject var weatherViewModel = WeatherViewModel() private var city: Int = "2639577"   var body: some View {     ZStack {       BackgroundView()               VStack {         if weatherViewModel.stateView == .loading {           Show Loading           }         }                   if weatherViewModel.stateView == .success { DO something } } This call my WeatherViewModel class as following class WeatherViewModel: ObservableObject { private var city = "city from WeatherView"  private func getData() { do something } } Im really struggling to pass the city variable to the class. I need this to then call the API client. Could anyone shed some light on how to this this please. Thank you very much
1
0
347
Dec ’20