Skip to content

Instantly share code, notes, and snippets.

@kashfifahim
Created September 26, 2018 11:10
Show Gist options
  • Save kashfifahim/8a8a801acd645399ee92a964df24e58e to your computer and use it in GitHub Desktop.
Save kashfifahim/8a8a801acd645399ee92a964df24e58e to your computer and use it in GitHub Desktop.
// LoYoLocalMainVC.swift
// LoYoLo
//
// Created by iOS on 9/24/18.
// Copyright © 2018 Kashfi Fahim. All rights reserved.
//
import UIKit
import Alamofire
import SwiftyJSON
class LoYoLocalMainVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
//MARK: Outlets:
@IBOutlet weak var tableView: UITableView!
//MARK: Global Variables:
var listingArray = [AnyObject]()
//MARK: Defining the API URL
let API_URL = "https://data.cityofnewyork.us/resource/wfv8-7zbh.json"
override func viewDidLoad() {
super.viewDidLoad()
//MARK: Alamofire Network Request
Alamofire.request(API_URL).responseJSON { (responseData) -> Void in
if((responseData.result.value) != nil) {
let swiftyJsonVar = JSON(responseData.result.value!)
if let resData = swiftyJsonVar[].arrayObject {
self.listingArray = resData as [AnyObject];()
}
if self.listingArray.count > 0 {
self.tableView.reloadData()
}
}
}
} // End of viewDidLoad
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//MARK: Number of Rows
return listingArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! BusinessCell
//MARK: Data to cells
let name = listingArray[indexPath.row]
cell.nameOfBusinessLabel.text = name["name_of_business"] as? String
cell.shortDescriptionLabel.text = name["short_description"] as? String
cell.addressLabel.text = name["address"] as? String
cell.boroughLabel.text = name["borough"] as? String
return cell
}
} // End of VC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment