4 changed files with 159 additions and 2 deletions
@ -0,0 +1,63 @@ |
|||
// |
|||
// ListCategoryView.swift |
|||
// TabBarProject |
|||
// |
|||
// Created by Arthur Dambrine on 06/04/2021. |
|||
// |
|||
|
|||
import SwiftUI |
|||
|
|||
struct Category: Codable, Identifiable { |
|||
let id = UUID() |
|||
let id_categorie: Int |
|||
let nom: String |
|||
} |
|||
|
|||
class apiCall { |
|||
func getCategories(completion:@escaping ([Category]) -> ()) { |
|||
guard let url = URL(string: "https://api.art-dambrine.ovh/categories") else { return } |
|||
URLSession.shared.dataTask(with: url) { (data, _, _) in |
|||
let categories = try! JSONDecoder().decode([Category].self, from: data!) |
|||
print(categories) |
|||
|
|||
DispatchQueue.main.async { |
|||
completion(categories) |
|||
} |
|||
} |
|||
.resume() |
|||
} |
|||
} |
|||
|
|||
|
|||
struct ListCategoryView: View { |
|||
@State var categories: [Category] = [] |
|||
|
|||
var body: some View { |
|||
VStack { |
|||
Button { |
|||
print("buttonClicked") |
|||
apiCall().getCategories { (categories) in |
|||
self.categories = categories |
|||
} |
|||
} label : { |
|||
Text("Afficher les categories") |
|||
} |
|||
|
|||
List(categories) { categorie in |
|||
|
|||
Text(String(categorie.id_categorie)) |
|||
.font(.headline) |
|||
Text(categorie.nom) |
|||
.font(.subheadline) |
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
struct ListCategoryView_Previews: PreviewProvider { |
|||
static var previews: some View { |
|||
ListCategoryView() |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
// |
|||
// SettingsView.swift |
|||
// TabBarProject |
|||
// |
|||
// Created by Arthur Dambrine on 06/04/2021. |
|||
// |
|||
|
|||
import SwiftUI |
|||
|
|||
struct SettingsView: View { |
|||
@EnvironmentObject var user: User |
|||
|
|||
var body: some View { |
|||
|
|||
VStack{ |
|||
Text("Ici on peut modifier les reglages") |
|||
|
|||
Text("Score : \(user.score)") |
|||
Button("Increase"){ |
|||
self.user.score += 1 |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
struct SettingsView_Previews: PreviewProvider { |
|||
static var previews: some View { |
|||
SettingsView() |
|||
} |
|||
} |
Loading…
Reference in new issue