Skip to content

Instantly share code, notes, and snippets.

View Thonyvb's full-sized avatar
🎯

George Anthony Villacres Thonyvb

🎯
View GitHub Profile
@Thonyvb
Thonyvb / MainView.swift
Created March 18, 2022 19:39
SwiftUI Environment Object
struct MainView: View {
@StateObject var prices = Prices()
var body: some View {
VStack {
PricesView()
}.environmentObject(prices)
}
}
@Thonyvb
Thonyvb / CartView.swift
Created March 18, 2022 19:37
SwiftUI Property Wrapper ObservedObject
struct CartView: View {
@ObservedObject var prices: Prices
// …
@Thonyvb
Thonyvb / MainView.swift
Created March 18, 2022 19:36
SwiftUI Property Wrappers StateObject
struct MainView: View {
@StateObject var prices = Prices()
// …
@Thonyvb
Thonyvb / Prices.swift
Created March 18, 2022 19:34
SwiftUI ObservableObject
class Prices: ObservableObject {
@Published var prices: [Int]
// ... obtain prices via API
}
@Thonyvb
Thonyvb / ProductView.swift
Created March 18, 2022 19:32
SwiftUI Property Wrapper Binding
struct ProductView: View {
@State private var isFavorite: Bool = false
var body: some View {
// ...
FavButton(isFavorite: $isFavorite) // Pass a binding.
}
}
struct FavButton: View {
@Thonyvb
Thonyvb / BuyButton.swift
Created March 18, 2022 19:27
SwiftUI Property Wrappers
struct BuyButton: View {
@State private var isDisabled = true
var body: some View {
Button("Hacer la compra", action: {})
.buttonStyle(.borderedProminent) // apple's default for demonstration purposes.
.disabled(isDisabled)
}
}