Skip to content

Instantly share code, notes, and snippets.

View UmairSharif99's full-sized avatar

UmairSharif UmairSharif99

View GitHub Profile
@UmairSharif99
UmairSharif99 / DownloadAndSaveAudioFile.swift
Last active July 21, 2024 18:08
Function to download audio file from url and save it in documents directory
func downloadAndSaveAudioFile(_ audioFile: String, completion: @escaping (String) -> Void) {
//Create directory if not present
let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.libraryDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let documentDirectory = paths.first! as NSString
let soundDirPathString = documentDirectory.appendingPathComponent("Sounds")
do {
try FileManager.default.createDirectory(atPath: soundDirPathString, withIntermediateDirectories: true, attributes:nil)
print("directory created at \(soundDirPathString)")