Possible to write swift println logs into file too?
问题 Is it an easy way to write logs into a text file too? I need a crash log to analyse when something went wrong. But I already use println al around in the code. 回答1: Use String.writeToFile(<#path: String#>, atomically: <#Bool#>, encoding: <#NSStringEncoding#>, error: <#NSErrorPointer#>) You could add this: #if DEBUG func println(s:String) { var error:NSError? = nil let path = "/Users/<me>/dump.txt" var dump = String(contentsOfFile: path, encoding: NSUTF8StringEncoding, error: nil)! "\(dump)\n\