Skip to content

Instantly share code, notes, and snippets.

@dheerajn
Last active September 28, 2021 02:09
Show Gist options
  • Save dheerajn/0b1d717d6253a6334ead064c38fcd45e to your computer and use it in GitHub Desktop.
Save dheerajn/0b1d717d6253a6334ead064c38fcd45e to your computer and use it in GitHub Desktop.
extension View {
func debugOnlyModifier<T: View>(_ modifier: (Self) -> T) -> some View {
#if DEBUG
return modifier(self)
#else
return self
#endif
}
private var colors: [Color] {
[.blue, .yellow, .green, .red, .brown, .cyan, .gray, .indigo, .mint, .pink, .orange]
}
func debugOnlyBackground() -> some View {
debugOnlyModifier {
$0.background(Rectangle().foregroundColor(colors.randomElement()))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment