I have a ViewController and in these I would like to set an image as a background image via JSON URL.
I also wanted to present a picture of this JSON request with my JSON request which I already used for my News UITableViewController, but that did not work
Here is my code:
var courses = [Course]()
var activityIndicatorView: UIActivityIndicatorView!
var rows: [String]?
let dispatchQueue = DispatchQueue(label: "Example Queue")
let borderwidth = 10
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.hidesBackButton = true
fetchJSON()
}
// MARK: - Courses
struct Course: Codable {
let guid: GUID
let links: Links
enum CodingKeys: String, CodingKey {
case guid
case links = "_links"
}
}
// MARK: - GUID
struct GUID: Codable {
let rendered: String
}
// MARK: - Links
struct Links: Codable {
}
fileprivate func fetchJSON() {
let urlString = "EXAMPLE_URL"
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, _, err) in
DispatchQueue.main.async {
if let err = err {
print("Failed to get data from url:", err)
return
}
guard let data = data else { return }
do {
self.courses = try JSONDecoder().decode([Course].self, from: data)
self.tableView.reloadData()
} catch let jsonErr {
print("Failed to decode:", jsonErr)
}
}
}.resume()
}
I would like that the image occupies the entire ViewController and in the middle of a transparent box with welcome text However, I do not know how to load a picture from a post.