My app has two buttons, the first is calling a function that return a string and does some other stuff.
The second button has a function that takes the return String from the function one. Because the first function does other stuff as well, how can I store the return String in a variable for button two, so I don't have to call the function?
Example below, I want to avoid usingDirString (strUpper: returnDirString())
func returnDirString () -> String {
let dir = "/some/return/string"
return dir
}
func usingDirString (strUpper: String) {
print(strUpper)
}
struct ContentView: View {
var body: some View {
Button(action: {
returnDirString()
}) {
Text("First")
}
.padding()
Button(action: {
usingDirString (strUpper: returnDirString())
}) {
Text("second")
}
.padding()
}
}