Skip to content

Instantly share code, notes, and snippets.

@dasmido
Created March 21, 2018 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasmido/a278d05b6b9a6f78497e3f80ac82d0fd to your computer and use it in GitHub Desktop.
Save dasmido/a278d05b6b9a6f78497e3f80ac82d0fd to your computer and use it in GitHub Desktop.
NewsApp-JSON-MainVC
//
// MainVC.swift
// AlamofireJSON
//
// Created by Mohammed Jamal on 3/21/18.
// Copyright © 2018 Mohammed Jamal. All rights reserved.
//
import UIKit
import Alamofire
class MainVC: UIViewController {
var articcles = [Article]()
override func viewDidLoad() {
super.viewDidLoad()
self.downloadArticlesData {
}
}
func downloadArticlesData(completed: @escaping DownloadComplete){
// Download Forecast weather data for table view
Alamofire.request(BASE_URL, method: .get).responseJSON { response in
let result = response.result
if let dict = result.value as? Dictionary<String, AnyObject> {
if let articles = dict["articles"] as? [Dictionary<String, AnyObject>] {
// loop through each day to display information daily
for obj in articles {
let article = Article(articleDict: obj)
self.articcles.append(article)
print(obj)
}
//self.articcles.remove(at: 0)
//self.tableView.reloadData()
}
}
completed()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment