Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // IsSteamDown
- //
- // Created by Tyler Holley on 9/10/2018.
- // Copyright © 2018 Tyler Holley. All rights reserved.
- //
- import UIKit
- import Foundation
- // JSON parsing
- struct Welcome: Decodable {
- let greeting: String
- let instructions: [Instruction]
- }
- struct Instruction: Decodable {
- let statuses: [Status]
- let message, messageURL: String
- let status: Bool
- let load, time: Int
- enum CodingKeys: String, CodingKey {
- case statuses, message
- case messageURL = "message_url"
- case status, load, time
- }
- }
- struct Status: Decodable {
- let title: String
- let code: Int
- let status: Bool
- let time: Int
- }
- //main class
- class ViewController: UIViewController {
- //Hides the status bar
- override var prefersStatusBarHidden: Bool {
- return true
- }
- //Storyboard controllers
- @IBOutlet weak var downImage: UIImageView!
- @IBOutlet weak var upImage: UIImageView!
- //The meat of the program
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- let url = "https://issteamdown.com/status.json"
- let urlObj = URL(string: url)
- URLSession.shared.dataTask(with: urlObj!) {(data, response, error) in
- guard let data = data else { return }
- do {
- let json = try JSONDecoder().decode(Instruction.self, from: data)
- json.statuses.forEach { status in
- print(status)
- }
- } catch {
- print(error)
- }
- }.resume()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement