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

50 lines
1.1 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 = ""
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
Text(self.name)
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
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
}
}