且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift Playground - 文件不可读

更新时间:2023-02-02 07:54:11

首先要感谢 Nate Cook 的快速响应和可靠的答复.

I have to thank Nate Cook for first for his quick response and solid answer.

为了以防万一,我从另一个帖子中分享了他的回答,该标题具有误导性.

Just for case I share his answer from another post, which title is misleading.

在此处查看 Nate 的回答:https://***.com/a/26723557/2360439

See Nate's answer here: https://***.com/a/26723557/2360439

Playgrounds 是沙盒化的,因此您将无法从用户文件夹中的任何位置抓取文件.以下是如何将该文件添加到您的游乐场使其易于访问:

Playgrounds are sandboxed, so you won't be able to just grab files from anywhere in your user folder. Here's how to add that file to your playground to make it accessible:

  • 在 Finder 中找到您的.playground"文件,右键单击并选择显示包内容"
  • 您应该会看到timeline.xctimeline"、contents.xcplayground"和section-1.swift"
  • 创建一个名为Resources"的新文件夹(如果尚不存在).
  • 将您的文件复制到资源文件夹
  • Find your ".playground" file in the Finder Right click and choose "Show Package Contents"
  • You should see "timeline.xctimeline", "contents.xcplayground", and "section-1.swift"
  • Make a new folder called "Resources" if it doesn't exists yet.
  • Copy your files into Resources folder

似乎无法在 Playground 沙箱之外使用 Swift Playground 访问文件.如果您知道如何在沙箱外访问文件,欢迎分享您的解决方案!!

Seems that there is no way to access files with Swift Playground outside of Playground sandbox. If you know how to access files outside of sandbox, you are welcome to share your solution!!