Daily iOS
SwiftUI

View identity

In the code below, toggling isCompact wipes whatever was typed in the text field. Can you explain why using SwiftUI's concept of identity?

var body: some View {
    if isCompact {
        SearchField().padding(4)
    } else {
        SearchField().padding(16)
    }
}

Submit