From 46551258e263e923d78f44ef8628cc99d2ef4658 Mon Sep 17 00:00:00 2001 From: David Huh <38101884+qt1337@users.noreply.github.com> Date: Mon, 21 Dec 2020 22:26:20 +0100 Subject: [PATCH] :construction: --- DHBW-Service/Views/Tabs/HomeView.swift | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/DHBW-Service/Views/Tabs/HomeView.swift b/DHBW-Service/Views/Tabs/HomeView.swift index 10b984a..5a4b051 100644 --- a/DHBW-Service/Views/Tabs/HomeView.swift +++ b/DHBW-Service/Views/Tabs/HomeView.swift @@ -6,9 +6,14 @@ // import SwiftUI +import CoreData struct HomeView: View { @EnvironmentObject var settings: LocalSettings + @State var user: NSManagedObject = NSManagedObject() + + + var body: some View { VStack { @@ -18,6 +23,25 @@ struct HomeView: View { Text("First opening toggle") } Text("Test") + +// Text(user.value(forKey: "name") as! String) + + }.onAppear{ + self.readFromCoreData() + } + } +} + +extension HomeView{ + func readFromCoreData(){ + let managedContext = PersistenceController.shared.context + let fetchRequest = NSFetchRequest(entityName: "User") + + do { + try print(managedContext.fetch(fetchRequest)) + self.user = try managedContext.fetch(fetchRequest)[0] + } catch let error as NSError { + print(error) } } }