Skip to content

ShawnBaek/XRay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Platforms SPM License

XRay

Visual debugging tool for Apple platforms — inspect view hierarchies at runtime with color-coded overlays.

XRay shows all view hierarchies in UIKit without using Xcode's Debug View Hierarchy. Take a screenshot to trigger the overlay.

XRay debug view overlay

Status: Stable — feature complete. No active development needed.

Demo

XRay.mp4

Features

  • Recursively traverses entire view hierarchy
  • Color-coded labels by view type:
    • Red (center): ViewController
    • Blue (trailing bottom): Custom View
    • Black (leading top): Standard View
  • Complementary color borders for maximum contrast
  • Two filter modes: .all (full hierarchy) and .customClass (custom views only)
  • Debug-only — safely wrapped in #if DEBUG

Requirements

  • Swift 5.6+
  • iOS 11+

Installation

Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/ShawnBaek/XRay.git", from: "1.0.2")
]

Or in Xcode: File > Add Package Dependencies and enter:

https://github.com/ShawnBaek/XRay.git

Usage

1. Add Screenshot Notification Listener

In your AppDelegate.swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    #if DEBUG
    NotificationCenter.default.addObserver(
        self, selector: #selector(screenshotTaken),
        name: UIApplication.userDidTakeScreenshotNotification, object: nil
    )
    #endif
    return true
}

2. Handle the Screenshot Event

#if DEBUG
@objc func screenshotTaken() {
    guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
          let keyWindow = scene.keyWindow,
          let topViewController = keyWindow.topViewController() else {
        return
    }
    let xray = XRay(rootViewController: topViewController)
    xray.captureXray(classNameOption: .all)
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
        xray.removeXray()
    }
}
#endif

ClassNameOption

.all — Shows all view hierarchies

.customClass — Shows custom views only

License

MIT License. See LICENSE for details.

Author

Shawn Baek — GitHub · shawn@shawnbaek.com

About

Visual debugging tool for Apple platforms — inspect view hierarchies at runtime with color-coded overlays

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages