Categories
Blog

Video in SwiftUI: macOS

One of the great features of SwiftUI is that the same code can run on iOS and macOS. After all, you are just declaring what kind of views you want; the system will translate those to the adequate component according to the system.

So how can we make our Video view compatible with macOS?

Categories
Blog Code

Logging in Swift

Here is my poor man version of logging for SWIFT

func logPrint(logMessage: Any, _ file: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) {
    print("\(file):\(line):0: \(function): \(logMessage)")
}

This method besides printing your message it shows the file name, the line and the function method where the log was made. The file, function and line numbers are extracted using literal expressions.

This makes it easier to find where the log message come from and if you have the KZLinkedConsole plugin installed in Xcode you just need to click on the error message in the console and Xcode will take you there.

For a more advanced logging library I recommend XCGLogger

== Update (2016-01-25) ==

I found out that the print statement doesn’t print to the System Logs, this could be useful in scenarios that you want to see the log message on a user device. So I update my method to use the NSLog function

func logPrint(logMessage: Any, _ file: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) {
    NSLog("\(file):\(line):0: \(function): \(logMessage)")
}