//
// ViewController.swift
// WOEID
//
// Created by Park on 11/21/15.
// Copyright © 2015 Park. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var aTableView: UITableView!
let importer: WOEIDImporter = WOEIDImporter()
var woeidList: [WOEID]! = nil
var woeid: WOEID! = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “WOEID”
//woeidList = importer.loadDataFromCSV(“WOEIDList”)
importer.loadDataFromXML(“WOEIDList”)
woeidList = importer.woeidList
aTableView.delegate = self
aTableView.dataSource = self
aTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: “cell”)
let tempList = importer.loadData() // test data
importer.exportDataToCSV(tempList, path: “temp”)
importer.exportDataToPList(tempList, path: “temp”)
importer.exportDataToJSON(tempList, path: “temp”)
importer.exportDataToXML(tempList, path: “temp”)
//importer.loadDataFromJSON(“WOEIDJSON”)
/*let tempList2 :[WOEID] = importer.loadDataFromPList(“WOEIDPropertyList”)
for e in tempList2 {
print(e.description)
}*/
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return woeidList.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: UITableViewCell = aTableView.dequeueReusableCellWithIdentifier(“cell”) as UITableViewCell!
let woeid = woeidList[indexPath.row] as WOEID
cell.textLabel?.text = “\(woeid.code) \(woeid.city) \(woeid.country)”
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
print(cell.textLabel?.text)
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
tableView.deselectRowAtIndexPath(indexPath, animated: true)
print(“You selected cell #\(indexPath.row)”)
woeid = woeidList[indexPath.row] as WOEID
self.performSegueWithIdentifier(“ShowSimpleVCSegue”, sender: self)
//let woeid = woeidList[indexPath.row] as WOEID
//let aViewController: SimpleViewController = storyboard?.instantiateViewControllerWithIdentifier(“SimpleViewController”) as! SimpleViewController
//aViewController.woeid = woeid
//navigationController?.pushViewController(aViewController, animated: true)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if (segue.identifier == “ShowSimpleVCSegue”) {
if let destinationVC = segue.destinationViewController as? SimpleViewController {
print(“SimpleTableViewController”)
destinationVC.woeid = woeid
}
}
}
}