Skip to content

Instantly share code, notes, and snippets.

@augusteo
Created July 23, 2015 05:43
Show Gist options
  • Save augusteo/c4e8e0238003e371ab6d to your computer and use it in GitHub Desktop.
Save augusteo/c4e8e0238003e371ab6d to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// RegionIndustryCSV
//
// Created by vic on 15/07/2015.
// Copyright (c) 2015 augusteo. All rights reserved.
//
import UIKit
import CSwiftV
import SwiftCSV
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var error:NSError?
let industryUrl = getCsvUrl(.Industry)
if let industryCsv = CSV(contentsOfURL: industryUrl, error: &error) {
println(industryCsv.headers)
}
}
// This func returns proper URL, guaranteed
func getCsvUrl(type: CsvType) -> NSURL {
switch type {
case .Region:
return NSURL(string: NSBundle.mainBundle().pathForResource("RegionData", ofType: "csv")!)!
case .Industry:
// return NSURL(string: NSBundle.mainBundle().pathForResource("IndustryData", ofType: "csv")!)!
return NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("IndustryData", ofType: "csv")!)!
}
}
// Only two case
enum CsvType { case Region, Industry }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment