mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-11-01 08:53:58 +00:00
56 lines
1.3 KiB
Swift
56 lines
1.3 KiB
Swift
//
|
|
// HomeView.swift
|
|
// DHBW-Service
|
|
//
|
|
// Created by Patrick Müller on 21.12.20.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
struct HomeView: View {
|
|
@EnvironmentObject var settings: LocalSettings
|
|
@State var user: NSManagedObject = NSManagedObject()
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Button(action: {
|
|
self.settings.isFirstOpening = !self.settings.isFirstOpening
|
|
}){
|
|
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<NSManagedObject>(entityName: "User")
|
|
|
|
do {
|
|
try print(managedContext.fetch(fetchRequest))
|
|
self.user = try managedContext.fetch(fetchRequest)[0]
|
|
} catch let error as NSError {
|
|
print(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct HomeView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
HomeView()
|
|
.preferredColorScheme(.dark)
|
|
.environmentObject(LocalSettings())
|
|
}
|
|
}
|