Created
November 30, 2023 11:46
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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