Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karigrooms/8b5f024ae82354db649321d6622d229d to your computer and use it in GitHub Desktop.
Save karigrooms/8b5f024ae82354db649321d6622d229d to your computer and use it in GitHub Desktop.
Blog: ObservableObjects and Protocols - Protocol usage in UIKit
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
import UIKit
class DemoController: UIViewController {
private let pricing: PriceRequesting
init(pricing: PriceRequesting) {
self.pricing = pricing
// ...
}
// ...
private func subscribe() {
// pricing.$price.sink { newPrice in
pricing.pricePublisher.sink { newPrice in
guard let price = newPrice else {
self.priceLabel.text = "Price not available"
return
}
self.priceLabel.text = "\(price.amount) \(price.description)"
}
.store(in: &subscriptions)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment