Swift游乐场没有沙盒

时间:2018-01-01 10:29:35

标签: swift sandbox nsurl swift-playground appstore-sandbox

我正在寻找有关macOS Swift Playgrounds如何处理沙盒的更多信息。我想测试一些macOS代码是如何在沙箱中运行的,但从我看到的情况来看,Playground不是沙箱,至少对于macOS来说。

https://stackoverflow.com/a/38987133/2778502表示iOS游乐场是沙盒,正如您所期望的那样。

但是,以下建议macOS游乐场也是沙箱:https://stackoverflow.com/a/31087421/2778502

为了测试这个,我在Xcode 9.2中创建了一个新的Swift macOS游乐场,并将以下代码放入其中。它基本上是检查/etc/hosts的“可达性”和可读性。我之所以选择该文件只是因为我想要一个我知道不应该从沙盒MacOS应用程序访问的文件。

//: Playground - noun: a place where people can play

import Cocoa

var directory = URL(fileURLWithPath: "/etc/hosts")

do {
    if try directory.checkResourceIsReachable() {
        print("file URL \(directory) is reachable")
    }
    else {
        print("file URL \(directory) returned false")
    }
} catch {
    print("file URL threw error: \(error)")
}

var isReadableFile = FileManager.default.isReadableFile(atPath: "/etc/hosts")

Swift告诉我文件网址是可以访问的,而isReadableFiletrue,即没有沙盒正在播放。

所以我的问题是:

  • 我认为沙盒对于iOS游乐场而不是macOS游乐场有效吗?
  • 是否可以打开macOS游乐场的沙盒?

0 个答案:

没有答案