Mathieu Rios
Mathieu Rios

Reputation: 386

Swift print is not showing in Debug Console

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.

Upvotes: 5

Views: 4314

Answers (2)

Mathieu Rios
Mathieu Rios

Reputation: 386

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.

Upvotes: 1

mbi
mbi

Reputation: 629

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)

Upvotes: 2

Related Questions