I have a class called "Entry".
in there I have different variables like Int, NSDate and Float.
I have an array "listData" which consist of these elements.
This "listData" is filling a TableView. How do I store and read this array? How would an implementation look like?
I have tried to iterate through the array and saving the single elements of the "Entry" class to put it back together while loading. It does not seem to work properly.
Here is some of my code:
My Entry Class:
import Foundation
class Entry {
let number : Int
let date : NSDate
let mileage : Int
let trip : Float
let speed : Float
let consumption : Float
init(number: Int, date: NSDate, mileage: Int, trip: Float, speed: Float, consumption: Float) {
self.number = number
self.date = date
self.mileage = mileage
self.trip = trip
self.speed = speed
self.consumption = consumption
}
}
Then I have a global variable for the array:
var listData = [Entry]()
On a second ViewController I have declared some Variables which take the input of Textfield, to save them to a new "Entry" Object, which will then be appended to the listData Array:
listData.append(Entry(number: number_pass, date: date_pass, mileage: mileage_pass, trip: trip_pass, speed: speed_pass, consumption: consumption_pass))
Everything else I have in code is just setting up and managing the Tableviews.
Is there a way to use UserDefaults? Or do I have to use CoreData?
Hope You can help! Cheers, Niklas