我很惊讶为什么两次调用我的结构!有人可以解释这个问题吗?无需绕过这个问题,只是好奇为什么会发生?
struct PerformanceTest: View {
var body: some View {
NavigationView {
NavigationLink(destination: Text("Next Page")) {
ButtonView()
myPrint("test----15------") //called once
}
}
}
}
struct ButtonView: View {
var body: some View {
VStack {
myPrint("test----16------") //why is it called two times!
Text("Oxygen")
.font(.title)
.foregroundColor(Color.red)
}
}
}
extension View {
func myPrint(_ vars: Any...) -> some View {
for v in vars { print(v) }
return EmptyView()
}
}