1
//GET text FROM SERVER
        let requestText = NSMutableURLRequest(url: URL(string: "Http://a.txt")!, ...)
      let sessionText = URLSession.shared
        let downloadText = sessionText.dataTask(with: requestText as URLRequest) {data,response,error in
......
            }

            DispatchQueue.main.async {
                //Update your UI here

          }
        }//dataTask
        downloadText.resume()

//GET pic FROM SERVER
        let requestText = NSMutableURLRequest(url: URL(string: "Http://a.jpg")!, ...)
      let sessionPic = URLSession.shared
        let downloadPic = sessionPic.dataTask(with: requestText as URLRequest) {data,response,error in
......
            }

            DispatchQueue.main.async {
                //Update your UI here

          }
        }//dataTask
        downloadPic.resume()

Hi, am not an expert in swift but I have a page the I would like to download pic (into UIImageView) and text (into UITextView) from a server. If I have multiple pics and text, must I run multiple session, request and Task.resume(), DispatchQueue.main.async ?

Is there way to get multiple request doing a single xxxx.resume()?

Thank you

lee
  • 31
  • 4
  • Possible duplicate of [How To Download Multiple Files Sequentially using NSURLSession downloadTask in Swift](http://stackoverflow.com/questions/32322386/how-to-download-multiple-files-sequentially-using-nsurlsession-downloadtask-in-s) – Nikunj Damani Mar 01 '17 at 08:49
  • Not related, but your data task does not need an explicit `URLRequest`. Just pass the `URL` – vadian Mar 01 '17 at 10:09

0 Answers0