5

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.

3
  • 3
    If I understand correctly, you are trying to print log in preview play. In the preview, you can not print anything. It will never work in preview. Commented Jan 19, 2021 at 17:54
  • You understood right. Then how I can print console logs ? I'm in Debugging live preview Commented Jan 20, 2021 at 8:21
  • 1
    I didn't check this. might be useful developer.apple.com/news/?id=8vkqn3ih Commented Jan 20, 2021 at 9:07

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.