Reputation: 36313
Is there a good reason that above returns nil in Playground? When run in AppDelegate the statements returns the file contents, but in Playground it's nil. Is it just another silly bug from Apple? Or just me not finding the docu which states that this is not allowed?
Upvotes: 1
Views: 2362
Reputation: 36313
It turned out that Playground was simply unwilling. Booo, Apple. I used the command
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
to get it going once again. A receipt I learned somewhere else on SO. This also cures a lot of other unwillingnesses of XCode.
Upvotes: 2
Reputation: 31016
Here's a playground example where I have created a file called "test" at the reported path:
let myPath = NSFileManager.defaultManager().currentDirectoryPath
let theData = NSData(contentsOfFile: "test")
let aString = NSString(data: theData!, encoding:4)
It displays...
"/Users/phil/Library/Containers/com.apple.dt.playground.stub.OSX.MyPlayground-C3A89455-96BA-4D37-A079-5893ED07EC92/Data"
{NSConcreteData}
{Some "Some text\n\n"}
...as the generated results.
Upvotes: 3