In SwiftUI.View body, accidentally put `padding()` (all by itself, no dot in front): it compiles fine, but preview doesn't work/run show blank screen or crash

Consider this code:

struct ModifierAccident: View {
    func myCustomSubview() -> some View {
        Text("Hello")
    }
    var body: some View {
        Group {
            myCustomSubview()
        }
    }
}

What is the difference between calling myCustomSubview() and padding() here? They're both instance methods, but one of them (padding()) uses self in its body, and the other one does not. This isn't really something the compiler can detect in the general case without some sort of annotation on methods like padding(). And such an annotation would be specifically tailored to SwiftUI's implementation details.

4 Likes