Last active
November 15, 2021 16:43
-
-
Save karigrooms/62b6208a8e034e2bf0e73c86a6e15d41 to your computer and use it in GitHub Desktop.
Blog: ObservableObjects and Protocols - Protocol with @published
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: ObservableObject { | |
var price: Price? { get } | |
func fetch() | |
} | |
class PricingProvider: PriceRequesting { | |
private(set) var price: Price? | |
init(price initialValue: Price? = nil) { | |
self.price = initialValue | |
} | |
func fetch() { | |
// TODO: fetch pricing from a service | |
let price = Int.random(in: 42...150) | |
self.price = Price(amount: "$\(price)", description: "avg/night") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment