3

I am having a problem with WidgetKit in Xcode 14 which is the debugger doesn't show any logs at all! even a simple print(). I have tried different ways

and other possible solutions found here! but still, no luck, have you any suggestions to fix this issue?

Mc.Lover
  • 4,813
  • 9
  • 46
  • 80

1 Answers1

1

It is no longer recommended to use print() to get messages to the console. It's a little more complicated now, but the new method also has some advantages.

Add the following to the top of your code.

import os.log

extension OSLog {
    private static var subsystem = Bundle.main.bundleIdentifier!

    /// Logs the view cycles like viewDidLoad.
    static let viewCycle = OSLog(subsystem: subsystem, category: "viewcycle")
}

Now you can do replace your print() statements with something like this:

Logger.viewCycle.info("View did load!")

If you open the standard MacOs console.app, you'll see the messages printed and can filter by device/category/process/message.

credit

gjmcginn
  • 11
  • 1