Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging SWIFT 2.0:将日志数据写入本地文件夹_Logging_Path_Directory_Local - Fatal编程技术网

Logging SWIFT 2.0:将日志数据写入本地文件夹

Logging SWIFT 2.0:将日志数据写入本地文件夹,logging,path,directory,local,Logging,Path,Directory,Local,我试图在不使用调试器的情况下遵循我的代码。执行时,当前文件夹与使用XCode环境时不同。所以我喜欢得到输出。因为我没有在终端中执行,所以没有输出窗口。所以我试着把它指向一个日志文件 func writeToDocumentsFile(fileNameOnly:String, value:String) -> Bool { let path = getDocPath(fileNameOnly) var error:NSError? do { try v

我试图在不使用调试器的情况下遵循我的代码。执行时,当前文件夹与使用XCode环境时不同。所以我喜欢得到输出。因为我没有在终端中执行,所以没有输出窗口。所以我试着把它指向一个日志文件

func writeToDocumentsFile(fileNameOnly:String, value:String) -> Bool {
    let path = getDocPath(fileNameOnly)
    var error:NSError?
    do {
        try value.writeToFile(path, atomically: true, encoding: NSUTF8StringEncoding)
    } catch let error1 as NSError {
        error = error1
    }
    return error == 0
}
这里我得到一个错误:

Optional(Error Domain=NSCocoaErrorDomain Code=4 "The folder “Log1.txt” doesn’t exist." UserInfo=0x600000260d80 {NSFilePath=/Users/dirk/Documents/Users/dirk/Library/Developer/Xcode/DerivedData/DSRenamer4-gopilcfgcwfqutabrktbxqhjornv/Build/Products/Debug/Log1.txt, NSUserStringVariant=Folder, NSUnderlyingError=0x6000000549d0 "The operation couldn’t be completed. No such file or directory"})
使用小包装器函数:

var output = ""

func LogToFile(file : String, text : String ) {

    output += text + "\r\n"

    writeToDocumentsFile(file, value: output)
}
此呼叫失败:

LogToFile(getCurrentPath("Log1.txt"), text: ">1>check plistfile >\(path)<")
LogToFile(getCurrentPath(“Log1.txt”),文本:“>1>检查plistfile>\(路径)