来自Server的Swift 3多个dataTask()

时间:2017-03-01 08:34:48

标签: swift3 nsmutableurlrequest

//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()

嗨,我不是swift的专家,但我有一个页面,我想从服务器下载pic(进入UIImageView)和文本(进入UITextView)。如果我有多个图片和文本,我必须运行多个会话,请求和Task.resume(),DispatchQueue.main.async?

有没有办法让多个请求执行单个xxxx.resume()?

谢谢

0 个答案:

没有答案