How would I go about adding multiple URL's? I wonder how I can set that up into an array with swift.
if let audioUrl = NSURL(string: "http://freetone.org/ring/stan/iPhone_5-Alarm.mp3") {
println("LOADING AUDIO")
if let myAudioDataFromUrl = NSData(contentsOfURL: audioUrl){
println("AUDIO LOADED")
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
let destinationUrl = documentsUrl.URLByAppendingPathComponent(audioUrl.lastPathComponent!)
println(destinationUrl)
if NSFileManager().fileExistsAtPath(destinationUrl.path!) {
println("The file already exists at path")
} else {
if myAudioDataFromUrl.writeToURL(destinationUrl, atomically: true) {
println("file saved")
} else {
println("error saving file")
}
}
}
}
In this case I think you should use NSURLSession.sharedSession().dataTaskWithURL to do multiple downloads from your links but keeping the download operation asynchronous. You need to add a callback block to it. You should do as follow: