问题
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.
来源:https://stackoverflow.com/questions/58751052/xcode-11-ios-playgrounds-no-longer-symlink-playgroundshareddatadirectory-bug-o