Advertisement
bluewizard3

isSteamDown v0.2

Sep 17th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.73 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  IsSteamDown
  4. //
  5. //  Created by Tyler Holley on 9/10/2018.
  6. //  Copyright © 2018 Tyler Holley. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Foundation
  11.  
  12. // JSON parsing
  13. struct Welcome: Decodable {
  14.     let greeting: String
  15.     let instructions: [Instruction]
  16. }
  17. struct Instruction: Decodable {
  18.     let statuses: [Status]
  19.     let message, messageURL: String
  20.     let status: Bool
  21.     let load, time: Int
  22.    
  23.     enum CodingKeys: String, CodingKey {
  24.         case statuses, message
  25.         case messageURL = "message_url"
  26.         case status, load, time
  27.     }
  28. }
  29. struct Status: Decodable {
  30.     let title: String
  31.     let code: Int
  32.     let status: Bool
  33.     let time: Int
  34. }
  35.  
  36. //main class
  37. class ViewController: UIViewController {
  38.    
  39.     //Hides the status bar
  40.     override var prefersStatusBarHidden: Bool {
  41.         return true
  42.     }
  43.    
  44.     //Storyboard controllers
  45.     @IBOutlet weak var downImage: UIImageView!
  46.     @IBOutlet weak var upImage: UIImageView!
  47.    
  48.     //The meat of the program
  49.     override func viewDidLoad() {
  50.         super.viewDidLoad()
  51.         // Do any additional setup after loading the view, typically from a nib.
  52.        
  53.         let url = "https://issteamdown.com/status.json"
  54.         let urlObj = URL(string: url)
  55.        
  56.         URLSession.shared.dataTask(with: urlObj!) {(data, response, error) in
  57.             guard let data = data else { return }
  58.             do {
  59.                 let json = try JSONDecoder().decode(Instruction.self, from: data)
  60.                 json.statuses.forEach { status in
  61.                     print(status)
  62.                 }
  63.             } catch {
  64.                 print(error)
  65.             }
  66.            
  67.         }.resume()
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement