Skip to content

Instantly share code, notes, and snippets.

@dfrobison
Last active November 29, 2022 17:30
Show Gist options
  • Save dfrobison/d42aa6957939714c9398736264d22d47 to your computer and use it in GitHub Desktop.
Save dfrobison/d42aa6957939714c9398736264d22d47 to your computer and use it in GitHub Desktop.
Debug printing from swiftUI
extension View {
func debugPrint(_ value: Any) -> some View {
#if DEBUG
print (value)
#endif
return self
}
// Example usage
struct ContentView: View {
var body: some View {
ScrollView {
ForEach(0..<100) { i in
Geometryreader { geo in
Text ("Row \i)")
.debugPrint ("Row \ (i) : \(geo. frame (in: •global))")
}
.frame (height: 50)
}
}
}
}
// Source: https://twitter.com/twostraws/status/1280996740053827584?s=43&t=yxrdWMTBTzKnT32NcqJ3jQ&utm_source=swiftlee&utm_medium=swiftlee_weekly&utm_campaign=issue_143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment