Last active
November 29, 2022 17:30
-
-
Save dfrobison/d42aa6957939714c9398736264d22d47 to your computer and use it in GitHub Desktop.
Debug printing from swiftUI
This file contains 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
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