Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created February 8, 2021 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/95a3214c98e34f1096ade8038bf581d1 to your computer and use it in GitHub Desktop.
Save sturdysturge/95a3214c98e34f1096ade8038bf581d1 to your computer and use it in GitHub Desktop.
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