People! Who in the subject tell me how to save the downloaded file in the correct application folder? There is a code for downloading a remote * .xml file .. how to save it? Which variable to pull out after downloading and build a save path for storing and rewriting, if necessary

let url = NSURL(string:"http://........./file.xml")! let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) in if error != nil { NSLog("%@", "Error: \(error)"); return } NSLog("Loaded %i bytes", data!.length) } task.resume() 

    1 answer 1

    solved my own question
    variable filename plain string

      let url:NSURL = NSURL(string: url_to_request)! let session = NSURLSession.sharedSession() let request = NSMutableURLRequest(URL: url) request.HTTPMethod = "POST" request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData let paramString = "data=Hello" request.HTTPBody = paramString.dataUsingEncoding(NSUTF8StringEncoding) let task = session.downloadTaskWithRequest(request) { ( let location, let response, let error) in guard let _:NSURL = location, let _:NSURLResponse = response where error == nil else { print("error") return } let urlContents = try! NSString(contentsOfURL: location!, encoding: NSUTF8StringEncoding) try! urlContents.writeToFile(filename, atomically: true, encoding: NSUTF8StringEncoding) guard let _:NSString = urlContents else { print("error") return } } task.resume()