I am trying to send NSLog to a file in Swift 3 running on Simulator, IOS 10.2 and nothing is being produced
How to NSLog into a file
func redirectCon
The absoluteString
property of an URL
produces an URL string, e.g.
file:///path/to/file.txt
which is not suitable as argument to freopen()
.
To get the file path as a string, use path
instead:
let logPath = dir.appendingPathComponent(file).path
Better, use the dedicated method to pass an URLs path to a system call:
let logFileURL = dir.appendingPathComponent(file)
logFileURL.withUnsafeFileSystemRepresentation {
_ = freopen($0, "a+", stderr)
}