Skip to content

carousell/DebugSwift

Β 
Β 

Repository files navigation

DebugSwift

DebugSwift is a comprehensive toolkit designed to simplify and enhance the debugging process for Swift-based applications
Image Image Image Image Image Image Image

πŸ“‹ Table of Contents

Requirements

  • iOS 14.0+
  • Swift 6.0+
  • Xcode 16.0+

Features

🌐 Network Inspector

  • HTTP Monitoring: Capture all requests/responses with detailed logs and filtering
  • WebSocket Inspector: Zero-config automatic monitoring of WebSocket connections and frames
  • Request Limiting: Set thresholds to monitor and control API usage
  • Smart Content: Automatic JSON formatting with syntax highlighting

⚑ Performance

  • Real-time Metrics: Monitor CPU, memory, and FPS in real-time
  • Memory Leak Detection: Automatic detection of leaked ViewControllers and Views
  • Thread Checker: Detect main thread violations with detailed stack traces
  • Performance Widget: Overlay displaying live performance stats

πŸ“± App Tools

  • Crash Reports: Detailed crash analysis with screenshots and stack traces
  • Console Logs: Real-time console output monitoring and filtering
  • Device Info: App version, build, device details, and more
  • APNS Tokens: Easy access and copying of push notification tokens
  • Custom Actions: Add your own debugging actions and info

🎨 Interface Tools

  • Grid Overlay: Visual alignment grid with customizable colors and opacity
  • View Hierarchy: 3D interactive view hierarchy inspector
  • Touch Indicators: Visual feedback for touch interactions
  • Animation Control: Slow down animations for easier debugging
  • View Borders: Highlight view boundaries with colorization

πŸ“ Resources

  • File Browser: Navigate app sandbox and shared app group containers
  • UserDefaults: View and modify app preferences at runtime
  • Keychain: Inspect keychain entries
  • Database Browser: SQLite and Realm database inspection
  • Push Notifications: Simulate push notifications with templates and test scenarios

Installation & Setup

Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/DebugSwift/DebugSwift.git", from: "2.0.0")
]

Basic Setup

import DebugSwift

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    private let debugSwift = DebugSwift()
    
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        
        #if DEBUG
        debugSwift.setup()
        // debugSwift.setup(disable: [.leaksDetector])
        debugSwift.show()
        #endif
        
        return true
    }
}

Shake to Toggle (Optional)

extension UIWindow {
    open override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
        super.motionEnded(motion, with: event)
        
        #if DEBUG
        if motion == .motionShake {
            if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
                appDelegate.debugSwift.toggle()
            }
        }
        #endif
    }
}

Examples

App Custom ViewControllers in Tab Bar

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

    let controller2 = UITableViewController()
    controller2.title = "Custom TableVC 2"
    return [controller1, controller2]
}

Custom Debug Actions

// Add custom debugging actions
DebugSwift.App.shared.customAction = {
    [
        .init(title: "Development Tools", actions: [
            .init(title: "Clear User Data") {
                UserDefaults.standard.removeObject(forKey: "userData")
            },
            .init(title: "Reset App State") {
                // Your reset logic here
            }
        ])
    ]
}

APNS Token Integration

// In your AppDelegate
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    DebugSwift.APNSToken.didRegister(deviceToken: deviceToken)
    // Your existing token handling code
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    DebugSwift.APNSToken.didFailToRegister(error: error)
    // Your existing error handling code
}

Configuration

Network Filtering

// Ignore specific URLs
DebugSwift.Network.shared.ignoredURLs = ["https://analytics.com"]

// Monitor only specific URLs
DebugSwift.Network.shared.onlyURLs = ["https://api.myapp.com"]

Selective Features

debugSwift.setup(
    hideFeatures: [.performance, .interface], // Hide specific tabs
    disable: [.leaksDetector, .console]       // Disable specific monitoring
)

App Group Configuration

// Configure app groups for file browser access
DebugSwift.Resources.shared.configureAppGroups([
    "group.com.yourcompany.yourapp"
])

Performance Monitoring

// Configure memory leak detection
DebugSwift.Performance.shared.onLeakDetected { leakData in
    print("πŸ”΄ Memory leak detected: \(leakData.message)")
}

Push Notification Simulation

// Enable push notification simulation
DebugSwift.PushNotification.enableSimulation()

// Simulate a notification
DebugSwift.PushNotification.simulate(
    title: "Test Notification",
    body: "This is a test notification"
)

⭐ Support the Project

If you find DebugSwift helpful, please consider giving us a star on GitHub! Your support helps us continue improving and adding new features.

GitHub stars

Contributors

Our contributors have made this project possible. Thank you!

Contributing

Contributions are welcome! If you have suggestions, improvements, or bug fixes, please submit a pull request. Let's make DebugSwift even more powerful together!

Repo Activity

Alt

Star History

Star History Chart

License

DebugSwift is licensed under the MIT License - see the LICENSE file for details.

About

A toolkit to make debugging iOS applications easier πŸš€

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.9%
  • Ruby 0.1%