You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
//
|
|
// ContentView.swift
|
|
// NavigationExemple
|
|
//
|
|
// Created by Arthur Dambrine on 02/04/2021.
|
|
//
|
|
|
|
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 {
|
|
@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: ChangeView()){
|
|
Text("Show detail view")
|
|
}
|
|
|
|
|
|
}.navigationTitle("Menu principal")
|
|
}
|
|
// Important à ajouter
|
|
.environmentObject(user)
|
|
|
|
}
|
|
}
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|
|
|