【问题标题】:Xcode Playgrounds Shared Directory Not WorkingXcode Playgrounds 共享目录不工作
【发布时间】:2019-09-17 19:35:22
【问题描述】:

创建 Xcode Playground 时,支持的 playgroundSharedDataDirectory 无法正确显示我预期的目录。

预期:~/Documents/Shared Playground Data

实际:file:///var/folders/46/zg_mg07d5h5_9t6q_4vr9_2w0000gn/T/com.apple.dt.Xcode.pg/containers/com.apple.dt.playground.stub.iOS_Simulator.MyPlayground-BEF6F13E-994E- 45C9-A18E-7DE953069D69/Documents/Shared%20Playground%20Data/

import UIKit
import PlaygroundSupport

print(playgroundSharedDataDirectory)

这也没有链接到目录。如果我将文件放在正确的目录中,我将无法读取它。如果我将它放在目录中,它确实可以工作,但每次加载 Playground 时它都会改变。

Xcode 10.3,也出现在 Xcode 11 中。这在 10.2 中有效

【问题讨论】:

  • playgroundSharedDataDirectory 指向不同的路径,具体取决于您选择的是 iOS 还是 macOS 游乐场。 Xcode 11 不会自动进行符号链接。问题:iOS 中的 Playgrounds 每次都会创建一个新的 Document 目录,并且不会与 User/:user/Document 目录进行符号链接。 PlaygroundSharedDataDirectory 将包含“共享数据目录”的路径,该路径将不存在,因为您不会每次都创建一个新文件夹,对吧?最好使用FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
  • 但这很痛苦。

标签: swift xcode swift-playground xcode10 xcode11


【解决方案1】:

这就是 iOS Playground 使用的路径。如果你创建一个 macOS Playground,它的路径是 ~/Documents/Shared Playground Data

【讨论】:

  • 所以,在 iOS 中 - 如果我想将我在 iOS 游乐场创建的文件(例如 audiorecording.wav)写入磁盘并从 iDevice 上的任何其他应用程序访问它,我在哪里有将.wav 文件存储到?在文件应用程序中打开操场容器文件时,我可以访问 iOS 操场/文件夹的 URL,或者我什至可以直接从我的代码写入文件应用程序中的任何位置吗?
猜你喜欢
  • 1970-01-01
  • 2021-09-25
  • 2015-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多