10

Xcode 11 Playgrounds seemingly changed the behavior of playgroundSharedDataDirectory:

To reproduce, paste the below in a playground and execute it in Xcode 10 and Xcode 11 respectively:

import PlaygroundSupport

print(playgroundSharedDataDirectory)
let str = try String(contentsOf: playgroundSharedDataDirectory.appendingPathComponent("data.json")) // assuming you create  ~/Documents/Shared Playground Data/data.json

playgroundSharedDataDirectory resolves to:

Xcode 11.2:

  • iOS: file:///Users/:username/Library/Developer/XCPGDevices/DB897D66-E542-44BD-B6CF-0176A3E480A9/data/Containers/Data/Application/2F952093-BD81-4B0C-AD45-8B5E45B4D7AB/Documents/Shared%20Playground%20Data/
  • macOS: file:///Users/:username/Documents/Shared%20Playground%20Data/

Xcode 10.2.1:

  • iOS: file:///var/folders/s7/x9ltynsn2zg_djfbtzszhn8d4zn6gb/T/com.apple.dt.Xcode.pg/containers/com.apple.dt.playground.stub.iOS_Simulator.MyPlayground-5985DF99-2BFE-45AC-9F34-70620F1DCD17/Documents/Shared%20Playground%20Data/
  • macOS: file:///Users/:username/Documents/Shared%20Playground%20Data/

Where in Xcode 10.2.1, iOS playgrounds symlink to ~/Documents/Shared Playground Data, it no longer does in Xcode 11+.

I'm wondering, is this an intentional change? If so, how can I access shared files from an iOS playground?

PS: I saw the answer to a related question (see https://stackoverflow.com/a/57981133/1324861), however, the answer isn't really applicable if the code I'm running requires an iOS playground.

opfeffer
  • 603
  • 5
  • 19
  • Have you gotten any further? I am also trying to find a URL that I can write a file (that my iOS Playground created) to and make this file accessible to other Apps on the iPad. Either by opening the Playground in a File Manager App and retrieving my file from some subdirectory there or from someplace in the Files App, in case it were accessible from within my Playground code. – mramosch Apr 15 '20 at 15:35

0 Answers0