Skip to content

Instantly share code, notes, and snippets.

@gungorbasa
Created November 30, 2023 11:46
Show Gist options
  • Save gungorbasa/49c7c9d3c9efb1210cfdc5d759bba89c to your computer and use it in GitHub Desktop.
Save gungorbasa/49c7c9d3c9efb1210cfdc5d759bba89c to your computer and use it in GitHub Desktop.
Create a debug border extension for SwiftUI code to understand when a view is redrawn.
//
// DebugBorder.swift
// Trial
//
// Created by Gungor Basa on 11/30/23.
//
import SwiftUI
extension View {
@ViewBuilder
func debugBorder() -> some View {
#if DEBUG
self.border(Color.random)
#else
self
#endif
}
}
private extension Color {
static var random: Color {
Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment