-
-
Save sturdysturge/8820d384f0d5eee9b27ca2f89566e347 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
class DataModel: ObservableObject { | |
static let url = URL(string: "https://xkcd.com/info.0.json")! | |
@Published var image: UIImage? = nil | |
@Published var xkcd: XKCD? = nil | |
func getImage() { | |
guard let url = URL(string: xkcd?.img ?? "") else {return} | |
if let data = try? Data(contentsOf: url) { | |
self.image = UIImage(data: data) | |
} | |
} | |
init() { | |
Self.url.getFromPublisher(property: &$xkcd) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment