Reputation: 598
I have an issue, I created a function to save an audio file to directory and the URL String to SwiftData. All works fine but if I recompile the app the audio file seems can't be found again?
Here is the setup of the recorder
func setupRecorder() throws {
let recordSettings = [AVFormatIDKey: Int(kAudioFormatMPEG4AAC_HE), AVSampleRateKey: 44100, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue] //as [String : Any]
let documentPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let audioFileName = documentPath.appendingPathComponent("audio_"+"\(self.fileName)"+"_recording.m4a")
audioRecorder = try AVAudioRecorder(url: audioFileName, settings: recordSettings)
audioRecorder.prepareToRecord()
}
-> Note: fileName is just a random UUID().string
Here is how I extract the url into a string to save it in SwiftData
func saveRecording() -> String {
guard let url = recordingList.last else { return "" }
let strURL = url.absoluteString
return strURL
}
So, after all this works and I can also close the app and open and the file is there but only after I recompile the project the file cannot be found again? Any ideas?
I created another app similar to this one but only saving images and I don't have the issue there.
Upvotes: -1
Views: 34