PreviousRecordings.swift (1329B)
1 // 2 // PreviousRecordings.swift 3 // captainsLog 4 // 5 // Created by Benjamin Welner on 10/28/19. 6 // Copyright © 2019 FIGBERT Industries. All rights reserved. 7 // 8 9 import SwiftUI 10 11 struct PreviousRecordings: View { 12 @EnvironmentObject var globalVars: GlobalVars 13 @ObservedObject var audioRecorder: AudioRecorder 14 15 var body: some View { 16 Form { 17 ForEach(audioRecorder.recordings, id: \.createdAt) { recording in 18 RecordingRow(audioURL: recording.audioURL, createdAt: recording.createdAt, title: recording.title, number: recording.number) 19 } 20 .onDelete(perform: delete) 21 } 22 .navigationBarTitle( 23 Text("Recordings"), 24 displayMode: .inline 25 ) 26 .navigationBarItems(trailing: EditButton()) 27 } 28 func delete(at offsets: IndexSet) { 29 var urlsToDelete = [URL]() 30 for index in offsets { 31 urlsToDelete.append(audioRecorder.recordings[index].fileURL) 32 urlsToDelete.append(audioRecorder.recordings[index].audioURL) 33 } 34 audioRecorder.deleteRecording(urlsToDelete: urlsToDelete) 35 } 36 } 37 38 struct PreviousRecordings_Previews: PreviewProvider { 39 static var previews: some View { 40 PreviousRecordings(audioRecorder: AudioRecorder()).environmentObject(GlobalVars()) 41 } 42 }