Created
April 8, 2020 18:26
-
-
Save tachoknight/57311aa007742a3dae7669b7c4bba5c7 to your computer and use it in GitHub Desktop.
Why is callFruit() being called on instantiation?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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