swift3 Playground 未能获得路径的沙盒扩展
Posted
技术标签:
【中文标题】swift3 Playground 未能获得路径的沙盒扩展【英文标题】:swift3 playground failed to obtain sandbox extension for path 【发布时间】:2017-02-19 07:46:19 【问题描述】:当我在 Playground 中创建 ImageView 时,它显示“沙盒扩展”错误。
let url = URL(string: "http://www.objc.io/images/covers/16.jpg")!
let image = CIImage(contentsOf: url)!
let imageView = UIImageView(frame: image.extent)
imageView.image = UIImage(ciImage: image )
PlaygroundPage.current.liveView = imageView
控制台消息:
2017-02-19 15:37:06.803 Chapter2[73915:885328] Failed to obtain sandbox extension for
path=/var/folders/3t/2tbk2tn96_v6_39rrjym3hsr0000gn/T/com.apple.dt.Xcode.pg/containers/
com.apple.dt.playground.stub.ios_Simulator.Chapter2-8E7AB6A8-3EF4-47C0-BDA2-117817EA2934/Library/Caches/
com.apple.dt.playground.stub.iOS_Simulator.Chapter2-8E7AB6A8-3EF4-47C0-BDA2-117817EA2934. Errno:1
【问题讨论】:
看到这个***.com/questions/28352674/… 【参考方案1】:关键在于将 URLCache 设置在 Playground 的沙箱中。
试试这个:
import Foundation
import PlaygroundSupport
import UIKit
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
func showObjIOImage()
guard let url = URL(string: "http://www.objc.io/images/covers/16.jpg") else
return
guard let image = CIImage(contentsOf: url) else
return
let imageView = UIImageView(frame: image.extent)
imageView.image = UIImage(ciImage: image )
PlaygroundPage.current.liveView = imageView
showObjIOImage()
【讨论】:
以上是关于swift3 Playground 未能获得路径的沙盒扩展的主要内容,如果未能解决你的问题,请参考以下文章
在 Playground 中的 swift 3 中添加延迟似乎不准确