Last active
November 15, 2021 16:42
-
-
Save karigrooms/8b5f024ae82354db649321d6622d229d to your computer and use it in GitHub Desktop.
Blog: ObservableObjects and Protocols - Protocol usage in UIKit
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
// 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