DHBW-Service-App/DHBW-Service/Views/Other/FirstOpeningSettings.swift

67 lines
2.4 KiB
Swift
Raw Normal View History

2020-12-21 20:01:12 +00:00
//
// FirstOpeningSettings.swift
// DHBW-Service
//
// Created by Patrick Müller on 21.12.20.
//
import SwiftUI
2020-12-21 20:48:26 +00:00
import CoreData
2020-12-21 20:01:12 +00:00
struct FirstOpeningSettings: View {
@EnvironmentObject var settings: LocalSettings
2020-12-21 20:48:26 +00:00
@State private var name = ""
@State private var course = ""
@State private var director = ""
2020-12-21 20:01:12 +00:00
var body: some View {
2020-12-21 20:48:26 +00:00
VStack {
TextField("Name", text: self.$name)
.textContentType(.name)
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center)
.padding(.horizontal)
TextField("Course", text: self.$course)
.textContentType(.name)
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center)
.padding(.horizontal)
TextField("Director", text: self.$director)
.textContentType(.name)
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center)
.padding(.horizontal)
Button(action: {
self.settings.isFirstOpening = !self.settings.isFirstOpening
}){
Text("Confirm")
.padding()
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(15)
}
2020-12-21 20:01:12 +00:00
}
}
}
2020-12-21 20:48:26 +00:00
extension FirstOpeningSettings{
func saveToCoreData(){
let entity = NSEntityDescription.entity(forEntityName: "User", in: PersistenceController.shared.context)!
let user = NSManagedObject(entity: entity, insertInto: PersistenceController.shared.context)
user.setValue(name, forKey: "name")
user.setValue(course, forKey: "course")
user.setValue(director, forKey: "director")
PersistenceController.shared.save()
}
}
2020-12-21 20:01:12 +00:00
struct FirstOpeningSettings_Previews: PreviewProvider {
static var previews: some View {
FirstOpeningSettings()
2020-12-21 20:48:26 +00:00
.preferredColorScheme(.dark)
.environmentObject(LocalSettings())
2020-12-21 20:01:12 +00:00
}
}