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
|
2020-12-22 10:30:41 +00:00
|
|
|
@State private var name: String = ""
|
2020-12-22 12:43:56 +00:00
|
|
|
@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 {
|
2020-12-22 12:43:56 +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{
|
2020-12-22 10:30:41 +00:00
|
|
|
func readFromCoreData() {
|
|
|
|
let fetchedData = UtilityFunctions.getCoreDataObject(entity: "User")
|
2020-12-21 21:26:20 +00:00
|
|
|
|
2020-12-22 10:30:41 +00:00
|
|
|
if(!fetchedData.isEmpty) {
|
|
|
|
let user = fetchedData[0]
|
|
|
|
self.name = user.value(forKey: "name") as! String
|
2020-12-22 12:43:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|