Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karigrooms/bff4dfa2592501968d3a0f1e01dabf25 to your computer and use it in GitHub Desktop.
Save karigrooms/bff4dfa2592501968d3a0f1e01dabf25 to your computer and use it in GitHub Desktop.
Blog: ObservableObjects and Protocols - Use type erasure to workaround Cuckoo mocking issue
// Copyright 2021 Expedia, Inc.
// SPDX-License-Identifier: Apache-2.0
import Combine
protocol PriceRequesting {
var price: Price? { get }
var pricePublisher: AnyPublisher<Price?, Never> { get }
func fetch()
}
class PricingProvider: PriceRequesting, ObservableObject {
@Published private(set) var price: Price?
var pricePublisher: AnyPublisher<Price?, Never> {
return $price.eraseToAnyPublisher()
}
init(price initialValue: Price? = nil) {
self.price = initialValue
}
func fetch() {
// .. fetch pricing from a service
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment