mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-11-01 08:53:58 +00:00
59 lines
1.6 KiB
Swift
59 lines
1.6 KiB
Swift
//
|
|
// LecturePlanItem.swift
|
|
// DHBW-Service
|
|
//
|
|
// Created by Patrick Müller on 01.02.21.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
struct LecturePlanItem: View {
|
|
@State var event: NSManagedObject
|
|
@State var isHidden = false
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text(event.value(forKey: "summary") as! String)
|
|
Button(action: {
|
|
event.setValue(!isHidden, forKey: "isHidden")
|
|
self.isHidden = !isHidden
|
|
PersistenceController.shared.save()
|
|
}){
|
|
if(self.isHidden){
|
|
Text("Show")
|
|
} else {
|
|
Text("Hide")
|
|
}
|
|
}
|
|
.padding()
|
|
.foregroundColor(.white)
|
|
.background(Color.blue)
|
|
.cornerRadius(15)
|
|
}
|
|
.onAppear{
|
|
self.isHidden = event.value(forKey: "isHidden") as! Bool
|
|
}
|
|
}
|
|
}
|
|
|
|
struct LecturePlanItem_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
LecturePlanItem(event: getPreviewEvent())
|
|
.preferredColorScheme(.dark)
|
|
.previewDevice("iPhone 12")
|
|
.environmentObject(getFirstOpening())
|
|
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
|
}
|
|
|
|
static func getFirstOpening() -> LocalSettings {
|
|
let settings = LocalSettings();
|
|
settings.isFirstOpening = false;
|
|
return settings
|
|
}
|
|
|
|
static func getPreviewEvent() -> NSManagedObject {
|
|
return UtilityFunctions.getCoreDataObject(entity: "RaPlaEvent", sortDescriptors: [])[0]
|
|
}
|
|
}
|