sergio250
06/05/2019, 3:42 PMstruct ContentView: View {
var body: some View {
Spacer().padding()
}
}
Is transformed into
▿ _ModifiedContent<Spacer, _PaddingLayout>
▿ content: Spacer
- minLength: Optional<CGFloat>.none
▿ modifier: _PaddingLayout
▿ edges: Set
- rawValue: 15
- insets: Optional<EdgeInsets>.nonesergio250
06/05/2019, 3:50 PMPadding component:
struct Padding<Content>: View where Content : View {
let content: Content
init(content: () -> Content) {
self.content = content()
}
var body: some View {
content.padding()
}
}
struct ContentView: View {
var body: some View {
Padding{
Spacer()
}
}
}sergio250
06/05/2019, 4:42 PMPadding { … } syntax is any more readable than view.padding(), it’s more explicit in that what we are doing is changing a view’s properties, not creating any more views. I guess that’s just a matter of taste, thoughsergio250
06/05/2019, 4:53 PMsergio250
06/05/2019, 5:02 PM