Hi! I'm working on an app where the user chooses 11 times an menu option, and after that the user chooses, the intention is that depending on what they chose, that there is a calculation of multiple int data and the result will be shown as text on the screen.
Currently every menu option is done. I've added an observable int file and when the preferred option is selected the int data that I've chosen will be changed.
So now I've got a lot of observable/observed int data but I don't know how to sum the int data.
Can you help me?
This is how I set-up the @observable data files:
import Foundation
import SwiftUI
class Select1Variable: ObservableObject {
@Published var Select1Variable = "Selecteer..."
}
'm not sure to have a full understanding of your code, but I would suggest:
- create a single class for ObservableObject, with all the observed value:
class ValueVariableVUUR: ObservableObject {
@Published var vuurZonValue = 0 // var name should start with lowercase
@Published var vuurMaanValue = 0
func sumValues() -> Int {
return vuurZonValue + vuurMaanValue
}
}
Pass the ValueVariableVUUR instance to the environment and use it in any view you need (see here is you need some info on using environment https://developer.apple.com/forums/thread/725355)