Last active
September 14, 2024 17:33
-
-
Save byJeevan/f67485bf380e86d4f87a723ac383827c to your computer and use it in GitHub Desktop.
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
SwiftUI Components & Extension that saves iOSDev time. | |
### UIKit is **EVENT-Driven** framework - We could reference each view in the hierarchy, update its appearance when the view is loaded or as a reaction on an event. | |
### SwiftUI is **Declarative, State Driven** framework - We cannot reference any view in the hierarchy, neither can we directly mutate a view as a reaction to an event. | |
Instead, we mutate the state bound to the view. Delegates, target-actions, responder chain, KVO .. replaced with Closures & bindings. |
To make Content view as parameter. A better way to build Generic views.
struct ContainerView<Content: View>: View {
@ViewBuilder var content: Content
var body: some View {
content
}
}
// Usage
ContainerView{
...
}
Debugging:
let _ = Self._printChanges()
print statement to trace view lifecyclelet _ = print("Update XYZView")
We use this print to trace whether the body of Particular view (eg. SpyView) is executed or not.
ref: https://sarunw.com/posts/how-to-do-print-debugging-in-swiftui/
To make fullscreen view to fill entire screen:
ZStack {
Text("Hello").background(.yellow)
}
.frame(maxWidth: .infinity, maxHeight: .infinity) // this is important
.background(.blue)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
☢️ A workaround calculated the height of ScrollView