Added base for lecture plan view

This commit is contained in:
2021-01-30 23:05:44 +01:00
committed by Patrick Müller
parent 81f9e8706c
commit 95f06cc87d
8 changed files with 323 additions and 4 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ struct HomeView: View {
extension HomeView{
func readFromCoreData() {
let fetchedData = UtilityFunctions.getCoreDataObject(entity: "User")
let fetchedData = UtilityFunctions.getCoreDataObject(entity: "User", sortDescriptors: [])
if(!fetchedData.isEmpty) {
let user = fetchedData[0]
@@ -0,0 +1,42 @@
//
// LecturePlanList.swift
// DHBW-Service
//
// Created by Patrick Müller on 30.01.21.
//
import SwiftUI
import CoreData
struct LecturePlanList: View {
@State private var events: [NSManagedObject] = []
var body: some View {
List {
ForEach(events, id: \.self) { event in
HStack {
Text(formatDate(date: event.value(forKeyPath: "startDate") as! Date))
Text(event.value(forKeyPath: "summary") as! String)
}
}
}.onAppear{
let sectionSortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
let sortDescriptors = [sectionSortDescriptor]
self.events = UtilityFunctions.getCoreDataObject(entity: "RaPlaEvent", sortDescriptors: sortDescriptors)
}
}
}
struct LecturePlanList_Previews: PreviewProvider {
static var previews: some View {
LecturePlanList()
}
}
extension LecturePlanList {
private func formatDate(date: Date) -> String {
let formatter = DateFormatter()
formatter.dateStyle = .short
return formatter.string(from: date)
}
}