1 Reply
      Latest reply on Jan 26, 2017 3:32 AM by eskimo
      acopalist Level 1 Level 1 (0 points)

        Please help me.

        I want to get an object of data from http.

        It works without problems with the code shown below.

        However, if you can not access http, it takes time to process "Data (contentsOf: url)".

        It will be around 20~30 seconds or so.

        Please tell me about how I can deal with something.



        let url = URL(string:"http://~~~~")!

        var image: UIImage = UIImage()

        autoreleasepool {

             guard let sampleData = try? Data(contentsOf: url) else {



             Image = UIImage(data: sampleData)!


        DispatchQueue.main.async {

             self.sampleView.image = Image



        • Re: Swift3 URL taking a long time to return with data
          eskimo Apple Staff Apple Staff (13,925 points)

          The most likely cause of this is networking delays.  As a first step, I recommend you fetch the data with an actual networking API, namely, URLSession, at which point you’ll be can get a high-level overview of the networking performance by way of the URLSessionTaskMetrics value.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"