According to How to find NSDocumentDirectory in swift? I wrote the next code:
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let files = NSFileManager().enumeratorAtPath(documentsPath)
var myString:String = "/"
while let file: AnyObject = files?.nextObject() {
myString += (file as String + "/")
}
println(myString)
But, actually the problem is that, when I debug the program, documentsPath equals to (String) "", after executing NSSearchPathForDirectoriesInDomains
command. Besides, I'm trying to do this not in MainViewController, I'm trying to execute this command in TableViewController.
However, it works in playground; It doesn't work for any project that I create
let docdir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String + "Test.txt"
returns the correct path, wtf?