 
 import UIKit
 import SnapKit
+import SwiftyJSON
+import Alamofire
 
 class NewsViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
 
     @IBOutlet weak var bigLbl: UILabel!
     @IBOutlet weak var subLbl: UILabel!
 
+    let newsURL = "https://toutiao.com/api/article/recent/?source=2&category=news_hot&as=A1D5D87595C3287"
+
     @IBOutlet weak var tableView: UITableView!
+
+    var messages = Array<Any>()
+
 
     override func viewDidLoad() {
         super.viewDidLoad()

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = UITableViewCell.init()
        cell.textLabel?.text = "hi"
        cell.contentView.backgroundColor = UIColor.init(red: 0.3, green: 0.4, blue: 0.5, alpha: 1)

        let view = UIView()
        view.backgroundColor = UIColor.red
        cell.contentView.addSubview(view)
        view.snp.makeConstraints { (make) in
            make.bottom.equalTo(cell.contentView.snp.bottom).offset(-20)
            make.right.equalTo(cell.contentView.snp.right).offset(-20)
            make.size.equalTo(CGSize(width: 100, height: 100))
            make.top.equalTo(cell.contentView.snp.top).offset(20)

        }

        return cell

        self.automaticallyAdjustsScrollViewInsets = false
        bigLbl.text = "News"
        subLbl.text = "some hot news"


        self.getNews()
      }

    func getNews() -> () {
        Alamofire.request(newsURL).responseJSON { (res) in
            if let result : Dictionary = res.value as? Dictionary<String,AnyObject>{
//                let data = JSON(result)["data"] as Array!
                for i in JSON(result)["data"]{
                    self.messages .append(i.1)
                    self.tableView .reloadData()
                }

            }
        }
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.messages.count
    }

    
