|
|
@ -7,27 +7,42 @@ |
|
|
|
|
|
|
|
import SwiftUI |
|
|
|
|
|
|
|
class User: ObservableObject { |
|
|
|
@Published var score = 0 |
|
|
|
} |
|
|
|
|
|
|
|
struct ChangeView: View { |
|
|
|
@EnvironmentObject var user: User |
|
|
|
|
|
|
|
var body: some View { |
|
|
|
VStack{ |
|
|
|
Text("Score : \(user.score)") |
|
|
|
Button("Increase"){ |
|
|
|
self.user.score += 1 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct ContentView: View { |
|
|
|
@State private var isShowingDetailView = false |
|
|
|
@ObservedObject var user = User() |
|
|
|
|
|
|
|
var body: some View { |
|
|
|
NavigationView{ |
|
|
|
|
|
|
|
VStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: 20){ |
|
|
|
Text("Score: \(user.score)") |
|
|
|
|
|
|
|
NavigationLink(destination: Text("Heads"), isActive: $isShowingDetailView){ |
|
|
|
EmptyView() |
|
|
|
NavigationLink(destination: ChangeView()){ |
|
|
|
Text("Show detail view") |
|
|
|
} |
|
|
|
|
|
|
|
Button("Tap to show view"){ |
|
|
|
// Some custom code here |
|
|
|
// .. |
|
|
|
self.isShowingDetailView = true |
|
|
|
} |
|
|
|
|
|
|
|
}.navigationTitle("Menu principal") |
|
|
|
} |
|
|
|
// Important à ajouter |
|
|
|
.environmentObject(user) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|