8

When creating an Xcode Playground, the supported playgroundSharedDataDirectory does not properly show my the expected directory.

Expected: ~/Documents/Shared Playground Data

Actual: 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)

This also does not link to the directory. If I place a file in the correct directory, I cannot read it. If I place it in the directory, it does work, but it changes every time the playground is loaded.

Xcode 10.3, also appears in Xcode 11. This worked in 10.2

Matthew Knippen
  • 1,048
  • 9
  • 22
  • 1
    The playgroundSharedDataDirectory points to different paths depending if you selected a iOS or macOS playground. Xcode 11 does not symlink automatically. Problems: the Playgrounds in iOS will create a new Document directory everytime and it will NOT symlink with the User/:user/Document directory. playgroundSharedDataDirectory will contains the path to “Shared Data Directory” which will not exist because you will not be creating everytime a new folder right? better to use `FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]` – multitudes Jan 21 '20 at 18:22
  • But this is pain. – Hope Aug 15 '20 at 12:16

1 Answers1

8

That's the path that iOS playground use. If you make a macOS playground it will have the path ~/Documents/Shared Playground Data

Craig Siemens
  • 12,942
  • 1
  • 34
  • 51
  • So, in iOS - if I want to write a file that I created in an iOS playground (e.g. audiorecording.wav) to disk and access it from any other application on the iDevice, where do I have to store the .wav file to? Is there a url for the iOS playground/folder that I can access when opening the playground container file in the files app, or can I even write to any place in the files app directly from my code? – mramosch Apr 08 '20 at 12:54