Skip to content

Instantly share code, notes, and snippets.

@tachoknight
Created April 8, 2020 18:26
Show Gist options
  • Save tachoknight/57311aa007742a3dae7669b7c4bba5c7 to your computer and use it in GitHub Desktop.
Save tachoknight/57311aa007742a3dae7669b7c4bba5c7 to your computer and use it in GitHub Desktop.
Why is callFruit() being called on instantiation?
struct ContentView: View {
static let fruits = ["apple", "pear", "banana"]
func callFruit() -> some View {
print("Getting called!")
return SomeOtherView(fruit: "apple")
}
var body: some View {
NavigationView {
List {
ForEach(ContentView.fruits, id: \.self) { fruit in
Text(fruit)
}
}.navigationBarTitle("Some Fruits").navigationBarItems(trailing: NavigationLink(destination: callFruit()) {
Text("Fruit")
})
}
}
}
struct SomeOtherView: View {
var fruit = ""
var body: some View {
Text(fruit)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment