I'm trying to make an iPhone app. On the first screen there is an item in a list which is "Show me a random number." I tap it and I'm taken to the second screen and on that screen it has the item and the answer. Like this.....
Show me a random number.
5
And then what I want to do is tap on that second "Show me a random number." and show another random number below it. Like this....
Show me a random number.
10
But how do I do this exactly? I've made the second "Show me a random number." a button. But then I don't know how to update the number. Here's my code....
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List {
Group {
NavigationLink(destination:Item1())
{Text ("Show me a random number.")}
}}
.font(.system(size: 18, weight: .semibold, design: .default))
.foregroundColor(.blue)
.textCase (nil)
.navigationTitle("My App")
.navigationBarTitleDisplayMode(.inline)
}}}
struct Item1: View {
var body: some View {
List {
Button(action: {
print("Button tapped.")
},
label: {
Text("Show me a random number.")
.font(.system(size: 18, weight: .semibold, design: .default))
let myrandom = Int.random(in: 1..<11)
Text(String(describing: myrandom))
.font(.system(size: 18, weight: .regular, design: .default))
})}}}
So if anyone can help me that would be great. Thanks!