Swift 3 Playground URLSession 异步中的 UIImage 灰色

A UIImage Gray in Swift 3 Playground URLSession Async

Bach 显示在 .playground 文件中,但显示为灰色。切换不同的 Result Display Modes 没有帮助。

import UIKit
import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution = true
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)

var theImage = UIImageView()
let urlNew = NSURL(string: "https://upload.wikimedia.org/wikipedia/commons/6/6a/Johann_Sebastian_Bach.jpg")


let task = URLSession.shared.dataTask(with: urlNew! as URL) { (data, response, error) -> Void in

    if error != nil {
        print("thers an error in the log")
    } else {

        DispatchQueue.main.async() {
            let image = UIImage(data: data!)
            theImage.image = image
        }
    }

}

task.resume()

用 Swift 3.0 在 .playground 中呈现巴赫或任何 UIImageView 的最佳方法是什么?

我弄清楚了您遇到的问题,并在此处创建了一个 playground 来说明:https://github.com/dtweston/Bach.playground

import UIKit
import PlaygroundSupport

// Toggle the code below to fade the image out or display it properly
//PlaygroundPage.current.needsIndefiniteExecution = true

let image = UIImage(named: "Johann_Sebastian_Bach.jpg")

基本上,当游乐场还在 运行 时,图像看起来已经褪色了。由于您将 needsInfiniteExecution 设置为 true,它总是显得褪色。