上面在Playground中返回nil是否有充分的理由?当在AppDelegate中运行时,语句返回文件内容,但在Playground中它是零。这只是Apple的另一个愚蠢的错误吗?或者只是我没有找到说明这是不允许的文件?
答案 0 :(得分:2)
这是一个游乐场示例,我创建了一个名为" test"在报告的路径上:
let myPath = NSFileManager.defaultManager().currentDirectoryPath
let theData = NSData(contentsOfFile: "test")
let aString = NSString(data: theData!, encoding:4)
显示......
" /Users/phil/Library/Containers/com.apple.dt.playground.stub.OSX.MyPlayground-C3A89455-96BA-4D37-A079-5893ED07EC92/Data"
{NSConcreteData}
{Some" some text \ n \ n&n 34;}
...作为生成的结果。
答案 1 :(得分:2)
事实证明,Playground根本不愿意。 Booo,Apple。我用了命令
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
再次开始。我在SO上的其他地方学到的收据。这也解决了许多其他不愿意使用XCode的问题。