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 MainView: View { | |
@StateObject var prices = Prices() | |
var body: some View { | |
VStack { | |
PricesView() | |
}.environmentObject(prices) | |
} | |
} |
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 CartView: View { | |
@ObservedObject var prices: Prices | |
// … |
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 MainView: View { | |
@StateObject var prices = Prices() | |
// … |
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
class Prices: ObservableObject { | |
@Published var prices: [Int] | |
// ... obtain prices via API | |
} |
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 ProductView: View { | |
@State private var isFavorite: Bool = false | |
var body: some View { | |
// ... | |
FavButton(isFavorite: $isFavorite) // Pass a binding. | |
} | |
} | |
struct FavButton: View { |