-
-
Save sturdysturge/95a3214c98e34f1096ade8038bf581d1 to your computer and use it in GitHub Desktop.
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
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