Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Combine
import Foundation
import UIKit
class DataModel: ObservableObject {
static let url = URL(string: "https://api.coingecko.com/api/v3/coins/dogecoin/tickers")!
static let imageURL = URL(string: "https://external-preview.redd.it/" +
"X-Zf_cxcp7v0EzRWQSG15blQWcsWUwa7wfVIVziAUc.jpg" +
"?auto=webp&s=35a8f32cf4fc14756a1adeb1f484259b78befc39")!
@Published var tickerData: TickerData?
@Published var image: UIImage?
@Published var lastRefreshed = ""
func refresh() {
Self.url.getFromPublisher(property: &$tickerData)
lastRefreshed = "Last refreshed: \(Date.currentTime)"
}
init() {
if let data = try? Data(contentsOf: Self.imageURL) {
image = UIImage(data: data)
}
refresh()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment