Developing an iOS app using DebugSwift is highly beneficial, as it provides powerful debugging tools specifically designed for Swift developers. This tool simplifies the debugging process by offering an intuitive interface to inspect variables, view complex data structures, and debug Swift code more efficiently. By making runtime debugging more accessible and improving code visibility during execution, DebugSwift helps reduce development time and is especially valuable for resolving issues in complex Swift applications.

In this post, we will demonstrate how to configure the tool, track API REST service calls, and explore some additional utilities.

Base project

 

Here’s a revised version of your text for improved clarity, grammar, and flow:


The base code for this project is a straightforward iOS list-detail application. It makes a request to the Rick and Morty API to retrieve character information and fetches their corresponding images. It’s as simple as that:

For installing DebugSwift SPM package just go to project settings, package dependencies: 

We need a sample user gesture to trigger the tool, the most common event is shake, so we will creat a new modifier for controlling this event on any view:

import SwiftUI
#if DEBUG
    import DebugSwift
#endif

@main
struct DebugSwiftAppDemoApp: App {

    var body: some Scene {
        WindowGroup {
            CharacterView()
                .onAppear {
                #if DEBUG
                    setupDebugSwift()
                #endif
            }
            .onShake {
                #if DEBUG
                    DebugSwift.show()
                #endif
            }
        }
    }

    fileprivate func setupDebugSwift() {
        DebugSwift
            .setup()
        // MARK: - Enable/Disable Debugger
        DebugSwift.Debugger.logEnable = true
        DebugSwift.Debugger.feedbackEnable = true
    }
}

This SwiftUI app integrates the DebugSwift framework for debugging purposes, enabled only in DEBUG mode. It displays a CharacterView in its main scene and includes features for debugging during development. When the view appears, it initializes the DebugSwift setup, enabling logging and user feedback. Additionally, a shake gesture triggers the display of the DebugSwift debugging interface, offering developers a quick way to access debugging tools.

The use of conditional compilation (#if DEBUG) ensures that all DebugSwift functionality is included only in development builds and excluded from production (RELEASE mode). This approach allows for powerful debugging capabilities during development while maintaining a clean and secure production build.

.onShake is a custom modifier that executes an action when a shake event is detected. The focus of this post is not to explain its implementation, but you can find a link to the repository at the end of the post.

 

Let's debug...

All setup is ready, if you deployed:

  • On a real device, just share once the app is presente.
  • On simulator, Simulator, Device, Shake:

 

It will appear an small button at the center left of the screen:

The number “21” displayed in the middle of the button represents the total number of API requests made so far. You can perform either a short press or a long press on the button. A long press opens the Debug View Hierarchy, which will be discussed in the upcoming sections, specifically in the context of using a device or simulator. For now, just perform a short press.

Network

The first screen presented is the Network view, which I personally use the most. It allows you to review API requests and responses, making it easier to determine whether a communication issue originates upstream (backend), downstream (frontend), or even both!

This is the ordered list of requests made by the app. The first request retrieves the characters, while the subsequent ones primarily fetch the .jpeg images for these characters. If we tap on the first element:

We can see detailed API headers, request, response, response times, and more. On the navigation bar, from left to right, there are three interesting options:

  1. Share this information
  2. Get the cURL command to execute the same request in the command line:
    bash:
    curl -X GET -H "" -d "" https://rickandmortyapi.com/api/character
  3. Copy this information to paste elsewhere.

Performance

It allows you to monitor CPU usage, memory usage, frames per second, and memory leaks in real-time.

User interface

There are many utilities related to the user interface, such as:

  • Colorized view borders (as shown in the picture below)
  • Slow animations
  • Show touches
  • Switch to dark mode

There is also a grid overlay utility that displays a grid, which can be quite useful for adjusting margins. In the screenshot below, I have set the grid to 20×20:

App resources

Is possible also review app resources, such as:

  • App folders (Document,  Library, SystemData, tmp) and its files
  • App user defalts
  • App secured data stored in Keychain

Extend debug tool

You heard well you can extend, the tool for presentin specific information from current App,  impelemnting actions that are specific on your app. In configuration section is where  the magic takes place:

fileprivate func setupDebugSwift() {
        DebugSwift
            .setup()
        // MARK: - Custom Info

        DebugSwift.App.customInfo = {
            [
                    .init(
                    title: "Info 1",
                    infos: [
                            .init(title: "title 1", subtitle: "subtitle 1")
                    ]
                )
            ]
        }

        // MARK: - Custom Actions

        DebugSwift.App.customAction = {
            [
                    .init(
                    title: "Action 1",
                    actions: [
                            .init(title: "action 1") { // [weak self] in
                            print("Action 1")
                        }
                    ]
                )
            ]
        }

        // MARK: Leak Detector

        DebugSwift.Performance.LeakDetector.onDetect { data in
            // If you send data to some analytics
            print(data.message)
        }

        // MARK: - Custom Controllers

         DebugSwift.App.customControllers = {
             let controller1 = UITableViewController()
             controller1.title = "Custom TableVC 1"

             let controller2 = UITableViewController()
             controller2.title = "Custom TableVC 2"

             return [controller1, controller2]
         }

        // MARK: - Enable/Disable Debugger
        DebugSwift.Debugger.logEnable = true
        DebugSwift.Debugger.feedbackEnable = true
    }

This is presented in the following way:

If your custom debug data is too complex, you can dedicate an entire view to it:

Just one more thing...

I mentioned at the beginning that you can also perform a long press after shaking to trigger the DebugSwift tool interface. Please try it now. You should see the View Hierarchy:

But also Debug View Hierarchy:

Conclusions

I hope that you have enjoyed same as me discovering succh useful tool. You can find the source code used in this post in the following repository.

References

Copyright © 2024-2025 JaviOS. All rights reserved