Last active
November 15, 2021 16:41
-
-
Save karigrooms/bff4dfa2592501968d3a0f1e01dabf25 to your computer and use it in GitHub Desktop.
Blog: ObservableObjects and Protocols - Use type erasure to workaround Cuckoo mocking issue
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 | |
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