import SwiftUI private let df: DateFormatter = { let df = DateFormatter() df.dateStyle = .short df.timeStyle = .medium return df }() struct LogView: View { @EnvironmentObject var log: Log var body: some View { List(log.logEntries) { entry in VStack(alignment: .leading) { HStack { Text(entry.level.description) Spacer() Text(df.string(from: entry.date)) }.font(.footnote) Text(entry.message) } } } } struct LogView_Previews: PreviewProvider { static var previews: some View { LogView() .environmentObject(Log()) } }