daxia.zhou
daxia.zhou

Reputation: 31

swift3 playground failed to obtain sandbox extension for path

when I create a ImageView in Playground, it show me "sandbox extension" error.

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

The console message:

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

Upvotes: 3

Views: 2607

Answers (1)

Mark Semsel
Mark Semsel

Reputation: 7155

The key is in setting URLCache to stay within the playground's sandbox.

Try this:

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

Upvotes: 7

Related Questions