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

56 lines
1.3 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
2020-12-21 21:26:20 +00:00
@State var user: NSManagedObject = NSManagedObject()
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(user.value(forKey: "name") as! String)
}.onAppear{
self.readFromCoreData()
}
}
}
extension HomeView{
func readFromCoreData(){
let managedContext = PersistenceController.shared.context
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "User")
do {
try print(managedContext.fetch(fetchRequest))
self.user = try managedContext.fetch(fetchRequest)[0]
} catch let error as NSError {
print(error)
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
}
}