This commit is contained in:
David Huh 2020-12-21 22:26:20 +01:00
parent 2ea4182e63
commit 46551258e2

View File

@ -6,9 +6,14 @@
// //
import SwiftUI import SwiftUI
import CoreData
struct HomeView: View { struct HomeView: View {
@EnvironmentObject var settings: LocalSettings @EnvironmentObject var settings: LocalSettings
@State var user: NSManagedObject = NSManagedObject()
var body: some View { var body: some View {
VStack { VStack {
@ -18,6 +23,25 @@ struct HomeView: View {
Text("First opening toggle") Text("First opening toggle")
} }
Text("Test") Text("Test")
// 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)
} }
} }
} }