designdebt.club
Menu
Design Debt Club

Debug your iOS native code with Mac Console

I work in React Native, and so I’m used to starting an app in the iOS simulator so that I can see my Javascript console.logs coming through into a browser console or in the terminal. However, sometimes the code your debugging is in native code.

Here’s how to see logs from native iOS code.

Make sure you’re logging something

In Native code…

    import OSLog
    let logger = Logger(subsystem: "com.yourcompany.yourapp", category: "yourCategory")

Subsystem: A reverse DNS string that identifies your app or a specific part of it.
**category**: A string that categorizes the log messages within your subsystem (e.g., “Networking”, “UI”, “DataPersistence”).

Example use:

logger.trace("This is a trace message.")
logger.debug("This is a debug message.")
logger.info("This is an info message.")
logger.notice("This is a notice message.")
logger.warning("This is a warning message.")
logger.error("This is an error message: \(error.localizedDescription)")
logger.critical("This is a critical error, potentially leading to a crash.")

View the logs

One you’re running your app on device, you can view the logs by opening the console.

  1. Cmd+Space
  2. Type console

There are a probably a lot of other logs coming through, so use the filter settings to limit logs by subsystem or category.

That’s it!