Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karigrooms/fa1283fe1bcc3548e1fd3a793687a1ae to your computer and use it in GitHub Desktop.
Save karigrooms/fa1283fe1bcc3548e1fd3a793687a1ae to your computer and use it in GitHub Desktop.
Blog: ObservableObjects and Protocols - Protocol with generic type in SwiftUI
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import SwiftUI
struct PriceView<PriceObservable>: View where PriceObservable: PriceRequesting {
@ObservedObject var pricing: PriceObservable
var body: some View {
Group {
if let price = pricing.price {
Text(price.amount).bold() + Text(" \(price.description)").font(.system(size: 12))
} else {
Text("Price not available")
.italic()
.foregroundColor(.gray)
}
}
.font(.system(size: 16))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment