I'm building a little utility to load a CSV file into my app and read the next value about 5 times per second (The csv file is from a sensor logger)
For this i'm using this csv library: https://github.com/naoty/SwiftCSV
Now, the performance/update rate suffers dramatically with csv files with more than a few lines. The problem is that i can't for the life of it figure out how to NOT load the csv file with each time i call SensorRecording.getDatapoints()
I'm guessing it should be a global class variable only loaded once, but adding the respective lines for the variables "csvURL" and "csv" at the top of the class declaration yields a strange
"SensorRecording.Type does not have a member named 'csvPath'
How could i store it in a global variable for that class?
Here's the SensorRecording class code:
import UIKit
class SensorRecording: UIViewController {
var cur: Int = 1
let csvPath = NSBundle.mainBundle().pathForResource("2014-09-21_23-25-32", ofType: "csv")
let csvURL = NSURL.fileURLWithPath(csvPath!)
let csv = CSV(contentsOfURL: csvURL!)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getDatapoints() -> NSDictionary {
let rows = csv.rows
if (cur == (csv.rows.count-1)) { cur = 1 } else { cur++ }
return csv.rows[cur]
}
Many thanks