Swift print is not showing in Debug Console

Viewed 1068

I'm trying to do a simple console log (the simplest that can possibly be) and I'm not even able to do that. I'm starting to lose my mind over the simplest thing. Here is my code :


struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .onAppear {
                // ApiClient().getParams()
                print("log")
            }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

I'm running a debug preview and nothing is showing in console. I'm already sorry for this question. Is there anything I'm doing wrong or not doing ?

Thank you in advance.

2 Answers

The answer was that you can't print in live preview mode (even in debugging mode). You have to build and run the simulator to show the console logs.

Sorry for the more-than-novice question.

I suggest you to read this excellent blog post about logging in Swift.

TL;DR: depending on your target iOS version you should use one of either os_log or Logger (iOS 14 only)

Related