When working with different view composition in SwiftUI, we can take two approaches:
- To use some @ViewBuilder function inside the view as a helper function:
@ViewBuilder func makeButtonLabel() -> some View {
if isPlaying {
PauseIcon()
} else {
PlayIcon()
}
}
- To create a different view for that UI piece:
struct SongRow: View {
var song: Song
@Binding var isPlaying: Bool
...
var body: some View {
HStack {
if isPlaying {
PauseIcon()
} else {
PlayIcon()
}
}
}
}
I wonder which one is better and how we can measure it?
Analytically, it seems to me the second one has better performance in bigger view chunks, especially we can see it in the preview's loading time, but I don't have any clue for it.