From f759ce5f040ed6377d4b12e69f8e277cbc33aadc Mon Sep 17 00:00:00 2001 From: David Huh <38101884+qt1337@users.noreply.github.com> Date: Wed, 23 Dec 2020 17:13:55 +0100 Subject: [PATCH] :sparkles: Added new View in TabView - also edited mock user --- DHBW-Service/CoreData/Persistence.swift | 12 ++++++++---- DHBW-Service/Views/ContentView.swift | 24 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/DHBW-Service/CoreData/Persistence.swift b/DHBW-Service/CoreData/Persistence.swift index 6bff296..584fb73 100644 --- a/DHBW-Service/CoreData/Persistence.swift +++ b/DHBW-Service/CoreData/Persistence.swift @@ -63,10 +63,14 @@ struct PersistenceController { static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext - for _ in 0..<10 { - let newItem = Item(context: viewContext) - newItem.timestamp = Date() - } + + // set mock user + let entity = NSEntityDescription.entity(forEntityName: "User", in: PersistenceController.shared.context)! + let user = NSManagedObject(entity: entity, insertInto: PersistenceController.shared.context) + user.setValue("Max Mustermann", forKey: "name") + user.setValue("TINF19B4", forKey: "course") + user.setValue("Dr. Mustermann", forKey: "director") + do { try viewContext.save() } catch { diff --git a/DHBW-Service/Views/ContentView.swift b/DHBW-Service/Views/ContentView.swift index 14c2b8f..7f2f875 100644 --- a/DHBW-Service/Views/ContentView.swift +++ b/DHBW-Service/Views/ContentView.swift @@ -14,7 +14,9 @@ struct ContentView: View { var body: some View { Group { - if(!settings.isFirstOpening) { + if(settings.isFirstOpening) { + FirstOpeningSettings() + } else { TabView(selection: $selection) { HomeView() .tabItem { @@ -24,9 +26,15 @@ struct ContentView: View { } } .tag(0) + HomeView() + .tabItem { + VStack { + Image(systemName: "gear") + Text("Settings") + } + } + .tag(1) } - } else { - FirstOpeningSettings() } } } @@ -36,9 +44,17 @@ extension ContentView{ } struct ContentView_Previews: PreviewProvider { + + static func getFirstOpening() -> LocalSettings { + let settings = LocalSettings(); + settings.isFirstOpening = false; + return settings + } + static var previews: some View { ContentView() .preferredColorScheme(.dark) - .environmentObject(LocalSettings()) + .environmentObject(getFirstOpening()) + .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) } }