0

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.

Mark Benningfield
  • 2,800
  • 9
  • 31
  • 31
Shinox
  • 107
  • 12
  • can't you just add a full screen UIImageView and set white background, Then when you receive the url just get the image data and put it to imageView – RJE May 23 '19 at 08:43
  • Here is your solution https://stackoverflow.com/a/52330296/462533. Please search thoroughly before posting a question – Shrey May 23 '19 at 08:50
  • I want to load it from a JSON post. Its not a single picture, because when the picture will be edited the picture in the app will be also edited. Thats the problem – Shinox May 23 '19 at 09:14

0 Answers0