mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-11-01 08:53:58 +00:00
43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
//
|
|
// 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)
|
|
}
|
|
}
|