I'm using a Playground based on OSX.
When I tried NSFileManager.defaultManager().currentDirectoryPath it returns / which is not my working directory.
This is the best way I've found (with the help of Zev Eisenberg).
You need a little bit of help. Add a file to your playground's resources; you can just create a text file by right-clicking "Resources" and choose "New File". Call it "Token.txt" for the following code to work.
let tokenPath = Bundle.main.url(forResource: "Token", withExtension: "txt")!.resolvingSymlinksInPath()
let playgroundPath = tokenPath.deletingLastPathComponent().deletingLastPathComponent()
playgroundPath will now be the path of your playground.
Pretty, eh?
(Tested on Xcode 10 beta 3.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With