DHBW-Service-App/DHBW-Service/Views/Tabs/HomeView.swift

64 lines
1.7 KiB
Swift
Raw Normal View History

2020-12-21 19:28:01 +00:00
//
// HomeView.swift
// DHBW-Service
//
// Created by Patrick Müller on 21.12.20.
//
import SwiftUI
2020-12-21 21:26:20 +00:00
import CoreData
2020-12-21 19:28:01 +00:00
struct HomeView: View {
2020-12-21 19:54:59 +00:00
@EnvironmentObject var settings: LocalSettings
@State private var name: String = ""
@State private var course: String = ""
@State private var director: String = ""
2020-12-21 19:54:59 +00:00
2020-12-21 19:28:01 +00:00
var body: some View {
2020-12-21 19:54:59 +00:00
VStack {
Button(action: {
self.settings.isFirstOpening = !self.settings.isFirstOpening
}){
Text("First opening toggle")
}
Text("Test")
2020-12-21 21:26:20 +00:00
HStack {
Text("name".localized(tableName: "General", plural: false) + ": ")
Text(self.name)
}
HStack {
Text("course".localized(tableName: "General", plural: false) + ": ")
Text(self.course)
}
HStack {
Text("director".localized(tableName: "General", plural: false) + ": ")
Text(self.director)
}
2020-12-21 21:26:20 +00:00
}.onAppear{
self.readFromCoreData()
}
}
}
extension HomeView{
func readFromCoreData() {
let fetchedData = UtilityFunctions.getCoreDataObject(entity: "User")
2020-12-21 21:26:20 +00:00
if(!fetchedData.isEmpty) {
let user = fetchedData[0]
self.name = user.value(forKey: "name") as! String
self.course = user.value(forKey: "course") as! String
self.director = user.value(forKey: "director") as! String
2020-12-21 19:54:59 +00:00
}
2020-12-21 19:28:01 +00:00
}
}
struct HomeView_Previews: PreviewProvider {
static var previews: some View {
HomeView()
2020-12-21 19:54:59 +00:00
.preferredColorScheme(.dark)
2020-12-21 20:48:26 +00:00
.environmentObject(LocalSettings())
2020-12-21 19:28:01 +00:00
}
}